Community Home Request Access Read Blogs Share Your Ideas Search Community View My Settings
Reply
Copper Elite Contributor
GCS
Posts: 39
Registered: ‎07-13-2010
Accepted Solution

How to perform an update to an entity object from client side code?

I have client side code that is executed via the common tasks.

After the code is finished I would like to update a record in the database.

In the client side script, I already have the ID of the record to be updated.

Is there a possibility either to call a business rule or something or to do any kind of server request to update the record?

Would sData be the right thing to perform this task?

Please use plain text.
Copper Elite Contributor
GCS
Posts: 39
Registered: ‎07-13-2010

Re: How to perform an update to an entity object from client side code?

[ Edited ]

I found a way to do this via the client side sData service:

 

// getting the service

var service = new Sage.SData.Client.SDataService(

  {
    serverName: window.location.host,
    virtualDirectory: 'sdata',
    applicationName: 'slx',
    contractName: 'dynamic',
    userName: 'admin',
    password: 'mypassword',
    json: true

  }

);

 

// getting the (in this case it's attachment) record to be updated by the attachment ID I selected before (strID)

 

var request = new Sage.SData.Client.SDataSingleResourceRequest(service)
  .setResourceKind('attachments')
  .setResourceSelector("'"+strID+"'");
  request.read(

  {
    success: function (entry)

    {

      // writing the new custom Id into a custom field in attachment
      entry.CustomID = strNewCustomId;

      // updating the selected record
      request.update(entry);
    }
 });


 

Please use plain text.
Copper Elite Contributor
GCS
Posts: 39
Registered: ‎07-13-2010

Re: How to perform an update to an entity object from client side code?

Is there a way to retrieve the credentials from anywhere instead of hardcoding them into the JavaScript?

Please use plain text.
Nickel Contributor
Posts: 56
Registered: ‎03-18-2010

Re: How to perform an update to an entity object from client side code?

Hi,

 

you can use callback...

 

http://msdn.microsoft.com/en-us/library/ms178208.aspx

 

Hope this help.

Libert Damien
Please use plain text.
Copper Elite Contributor
GCS
Posts: 39
Registered: ‎07-13-2010

Re: How to perform an update to an entity object from client side code?

I have solved this problem by using the credentials from the connection string and sending them to the JavaScript function as parameters.

Please use plain text.