The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Add two fields date and time and then auto populate this two data into another field

vinod6
Tera Contributor

I have two fields 1. error -- type is date and time 
                              2. SUN Mints---type is date and time 
I want to add two fields  and then data is auto- populated into 3 field
                             3. End date----type is date and time

vinod6_0-1742212938119.png

I wrote a script but it is not working could you please help on this 
Thaks for the support 

3 REPLIES 3

J Siva
Tera Sage

Hi @vinod6 

Could you please share your script?
It'll be helpful for others to debug.

Regards,
Siva

Shivalika
Mega Sage

Hello @vinod6 

 

Please share script. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

J Siva
Tera Sage

HI @vinod6 
I'm unsure about our script.
But i just tried in my PDI by using the below script and it worked.
Note: I've considered SLA definition table as a sample table to test your scenario. Please replace the table and field names as required.

var gt = new GlideRecord("contract_sla"); // replace with your table
gt.get('00e277560f6233004fbc309c4e767e1e'); // sys id of the record, replace with your record syid/logic

var str = gt.getDisplayValue('duration').toString(); // Duration field from SLA definition table
gs.print(str);
var days = str.split(" ")[0]; // Hours
var hr = str.split(" ")[2]; //Days
var min = str.split(" ")[4];//Mins

var hr_secs = parseInt(hr)*3600 + parseInt(min)*60; // converting hours and minutes to seconds

var up = gt.getDisplayValue('sys_updated_on'); // Picking the date field to add the duration 

var dt = new GlideDateTime(up);
dt.addDays(parseInt(days));
dt.addSeconds(parseInt(hr_secs));

gs.print(dt.getValue());

 

Result:

Sample record:

JSiva_0-1742214650405.png

Script output:

JSiva_1-1742214683314.png

 

Hope this helps.
Regards,
Siva