set date field of new record from current form date attribute using REST RRS feed

  • Question

  • Hi 

    I have a web resource in a form that by clicking on a button inside that form, new record is created using REST. New records fields are filled from the form which contains the the web resource. Every thing is ok but date attributes. 

    Say The form has field 'npDate' and I want to copy the exact value of that to new record field 'np_2_date'. It is being copied but with one day less than npDate. I log the value of 'npDate' to browser and it shows :

    Thu Mar 20 2014 00:00:00 GMT+0430 (Iran Daylight Time)

    but when I open newly created record form, I see that 'np_2_date' is one day less, like below:

    Would you help me please ?

    Thursday, March 20, 2014 9:53 AM

All replies

  • can you share the javascript code where you perform the copy of this field?

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, March 20, 2014 10:08 AM
  • I had to mention that I use this  library to work easier with CRM REST api

    Yes Here it is:

    function getItemValue(attname)
    	return window.parent.Xrm.Page.data.entity.attributes.get(attname).getValue();
      return null;
    	var OpportunityID=null;
    			var lkopp=window.parent.Xrm.Page.data.entity.attributes.get("new_opportunuity").getValue();
    		var tenderID = window.parent.Xrm.Page.data.entity.getId();
    			// make button active
    			var oppname;
    			var tenderName;
    			CrmRestKit.Retrieve( 'Opportunity', OpportunityID.replace('{','').replace('}',''), ['Name'] ).fail(function(){console.log('error accoured');} ).done( function ( data ) {
    				// Assert
    			} );
    			CrmRestKit.Retrieve( 'new_opportunitytender', tenderID.replace('{','').replace('}',''), ['new_name'] ).fail(function(){console.log('error accoured');} ).done( function ( data ) {
    				// Assert
    			} );
    		    var np_2_date=getItemValue("npDate");
    			var tenderlegal = {
    			'np_2_date': np_2_date,
    			'new_name': 'Legal Part Review',
    			var newlegalid;
    				CrmRestKit.Create( 'new_opportunitytenderlegal', tenderlegal, false )
    				.fail( function(){console.log('error accoured');} )
    				.done( function ( data, status, xhr ) { 
    				} );
    			//associate records

    Thursday, March 20, 2014 10:22 AM
  • This is a Javscript issue. It starts Months from 0 therefore in any calculation we have to add 1 to months in order to get correct value. Please add 1 to months in you code.

    Regards Faisal

    Thursday, March 20, 2014 11:28 AM
  • But as it seems, it added one unit to day, not month....

    If this is the case, how could I add 1 to months ?

    Thursday, March 20, 2014 1:00 PM