public function findId($code, $key = 'Code')
    {
        if ($this->isFillable($key)) {
            $format = ($this->url() == 'crm/Accounts' && $key === 'Code') ? '%18s' : '%s';
            if (preg_match('/^[\w]{8}-([\w]{4}-){3}[\w]{12}$/', $code)) {
                $format = "guid'$format'";
            } elseif (is_string($code)) {
                $format = "'$format'";
            }

            $filter = sprintf("$key eq $format", $code);
            $request = [
                '$filter'  => $filter,
                '$top'     => 1,
                '$select'  => $this->primaryKey(),
                '$orderby' => $this->primaryKey(),
            ];
            if ($records = $this->connection()->get($this->url(), $request)) {
                return $records[0][$this->primaryKey()];
            }
        }
    }
public function findId($code, $key = 'Code')
    {
        if ($this->isFillable($key)) {
            $format = ($this->url() == 'crm/Accounts' && $key === 'Code') ? '%18s' : '%s';
            if (preg_match('/^[\w]{8}-([\w]{4}-){3}[\w]{12}$/', $code)) {
                $format = "guid'$format'";
            } elseif (is_string($code)) {
                $format = "'$format'";
            }

            $filter = sprintf("$key eq $format", $code);
            $request = [
                '$filter'  => $filter,
                '$top'     => 1,
                '$select'  => $this->primaryKey(),
                '$orderby' => $this->primaryKey(),
            ];
            if ($records = $this->connection()->get($this->url(), $request)) {
                return $records[0][$this->primaryKey()];
            }
        }
    }
public function findId ( $ code , $ key = 'Code' ) { if ( $ this -> isFillable ( $ key ) ) { $ format = ( $ this -> url ( ) == 'crm/Accounts' && $ key === 'Code' ) ? '%18s' : '%s' ; if ( preg_match ( '/^[\w]{8}-([\w]{4}-){3}[\w]{12}$/' , $ code ) ) { $ format = "guid'$format'" ; } elseif ( is_string ( $ code ) ) { $ format = "'$format'" ; } $ filter = sprintf ( "$key eq $format" , $ code ) ; $ request = [ '$filter' => $ filter , '$top' => 1 , '$select' => $ this -> primaryKey ( ) , '$orderby' => $ this -> primaryKey ( ) , ] ; if ( $ records = $ this -> connection ( ) -> get ( $ this -> url ( ) , $ request ) ) { return $ records [ 0 ] [ $ this -> primaryKey ( ) ] ; } } }
Return the value of the primary key.

@param string $code the value to search for
@param string $key  the key being searched (defaults to 'Code')

@return string (guid)
Return the value of the primary key .