locked
Updating date attribute using OData RRS feed

  • Question

  • Hi Friends

    I am retrieving an entity data using OData, in which there is a date field. When I look at date format of date field I retrived, it is like following.

    'Wed Mar 19 09:30:00 UTC+0530 2014'

    So I just wanted to update this field with todays date, and I did something like following.

    var date = new Date('Wed Mar 19 09:30:00 UTC+0530 2014');


     Account.new_date=date ;

    But I am getting following error  :  

    "Error : 400: Bad Request: Error processing request stream. The property name 'new_date' specified for type 'Microsoft.Crm.Sdk.Data.Services.Account' is not valid."


    Thanks Regards Prashanth Kamasamudram Even the least work done for others awakens the power within; even thinking the least good of others gradually instills into the heart the strength of a lion.

    Wednesday, March 19, 2014 12:51 PM

All replies

  • You can use something like this:

    var entity = {};
    entity.LastUsedInCampaign = new Date().toLocaleString();
    
    var req = new XMLHttpRequest();
    req.open('POST', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'58791BDB-A0AE-E311-8A9D-6C3BE5A8CA94')"), true);
    req.setRequestHeader('Accept', 'application/json');
    req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
    req.setRequestHeader('X-HTTP-Method', 'MERGE');
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 204 || this.status == 1223) {
                alert('Updated'); //Success - Do Something
            }
            else {
                alert(this.statusText);
            }
        }
    };
    req.send(JSON.stringify(entity));


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, March 19, 2014 1:05 PM
    Moderator
  • account.new_Amount = price; //Address 1: Address Type = Primary account.new_Description={Value:803080001}; //var date =new Date().toLocaleString(); account.new_date=new Date().toLocaleString(); SDK.JQuery.updateRecord( accountId, account, "account", function () { }, errorHandler );

    HI  JLattimer,

                          I have used above code and assigned data as you mentioned in your reply, but still getting same error. If just update other fields its working fine. But I need to change date to current date.

    Any alternative approach. or am i doing something wrrng here


    Thanks Regards Prashanth Kamasamudram Even the least work done for others awakens the power within; even thinking the least good of others gradually instills into the heart the strength of a lion.


    Wednesday, March 19, 2014 2:23 PM