How to get date field value from one table and copy the same date into another table date field value??

naveenmyana
Giga Expert

Hellooo everyone,

I am trying to create a new change request from release module and i need to do the below task while doing so..

I have two date fields in release table called "Planned start date" and "Planned end date" and I need to reflect these dates same as in release table in the change table date fields called "Planned start date" and "Planned end date".

Here both date fields from both tables are having the same field names as "start_date" and "end_date".  

I have written the below client script code but it's not working for me, please suggest me a solution for this??

function onLoad() {

  //Type appropriate comment here, and begin script below

  var rel = g_form.getReference('rm_release', getdatevalues);

  g_form.setValue('u_reason_for_invoking_change','Release');

  g_form.setValue('start_date','start');

  g_form.setValue('end_date', 'end');

  function getdatevalues(){

              if(rel != '' & state == -5){

              var start = g_form.getValue('start_date');

            var end = g_form.getValue('end_date');

  }

  }

}

here's the output i got for the above code:

datefields.PNG

9 REPLIES 9

nishailame
ServiceNow Employee
ServiceNow Employee

Try below -



function onLoad() {


  //Type appropriate comment here, and begin script below



  var rel = g_form.getReference('rm_release');


  g_form.setValue('u_reason_for_invoking_change','Release');


 


              if(rel != '' & rel.state == -5){


                      g_form.setValue('start_date', rel.start_date);


                      g_form.setValue('end_date', re.end_date);


            }


}


 


Thanks.


PS: Hit like, Helpful, Correct and Endorse, if it answers your question.


Chuck Tomasi
Tera Patron

Are you looking to simply populate the default start/end date?



If so, you could use a display business rule to populate g_scratchpad with a couple properties and use them in the onLoad client script. Note, the below script is intended as an example and not a final solution. It is not tested and may require modifications to meet your needs (fields and tables.)



Display BR:


g_scratchpad.start_date = current.release.start_date.getDisplayValue();


g_scratchad.end_date = current.release.end_date.getDisplayValue();



In the onLoad client script:


g_form.setValue('start_date', g_scratchpad.start_date);


g_form.setValue('end_date', g_scratchpad.end_date);



You could also do this from the dictionary entry default value (be sure to check that the release date field is populated.



Reference episode 5 of TechNow for more information and examples:


TechNow Episode List


Tomasi,



I am looking to copy the whatever date fields values are there from release table to change table date field values, Not the default value...I have tried your code


but it's not working for me, can you please suggest me where i went wrong here..



Here's the code I have written..



function onLoad() {


  //Type appropriate comment here, and begin script below



  var rel = g_form.getReference('rm_release', getdatevalues);


  g_form.setValue('u_reason_for_invoking_change','Release');


  g_form.setValue('start_date','start');


  g_form.setValue('end_date', 'end');



  function getdatevalues(){


              if(rel != '' & state == -5){


              var start = g_form.getValue('start_date');


            var end = g_form.getValue('end_date');



  }


  }


}


The output i got here u can see in the screenshot I am attaching here FYI...datefields.PNG


Release table.PNGchange table.PNG


Hi Naveenmyana,



In that case, I would use this in the dictionary entry of the change request date fields. For this example, I'm using start_date. Repeat for any other date fields you want.



Right click on the change request start date field and choose Configure Dictionary.


In the default value field enter this:



javascript:(function () { if (current.parent) { return current.parent.start_date; } })();



Update.