Record producer Opened field

GBS
Tera Contributor

I have created a Record producer and used the below script to populate the field values except for the Opened field, the opened field has to be updated with the created on date. 

 

Script:

(function() {
   
    // Set the values to the incident fields
    current.u_opened_by = producer.requested_by;
    current.u_requested_for = producer.requested_for;
    current.u_assignment_group = '5a5c5e849312021029427e8efaba1041'; //group sys_id
    current.u_contact_type = "Self Service";
    current.u_item = '3a25637b47701100ba13a5554ee490a0';

    var createdOn = new GlideDateTime(current.sys_created_on.getDisplayValue());
    current.u_opened = createdOn.getDisplayValue();
    //current.u_opened = current.sys_created_on;
   
    current.u_state = 1;
    current.u_priority = 4;
 

})();

 

GBSaiKiran_0-1718281320673.png

 

1 ACCEPTED SOLUTION
5 REPLIES 5

Mark Manders
Mega Patron

Your 'created on' will be set at insert of the record, so there is no createdOn to set your u_opened field with. I would use an async BR to update the field after insert. It's created from the portal and the second it takes to update the field, won't be noticed by anyone.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Namrata Ghorpad
Mega Sage
Mega Sage

Hello @GBS ,

You can write the script like below.

current.u_opened=gs.nowDateTime();

Please refer the below links as well.

https://www.servicenow.com/community/developer-forum/how-to-auto-populate-date-field-on-record-produ... 

https://www.servicenow.com/community/developer-forum/field-with-today-s-date-on-record-producer/m-p/... 

https://www.servicenow.com/community/developer-forum/how-to-set-current-date-and-time/m-p/2223464 

 

Please mark my answer as correct and helpful if it helps you.

Regards,

Namrata

 

@Namrata Ghorpad Thanks, it worked