Populate duration field when state is resolved

Burhan2
Tera Contributor

Hi,

We have created a custom field 'total time' duration field. When incident state is resolved we want to populate that field with business duration field which is already present on incident table. I created business rule and onsbmit client script as well but that field is not auto populating with the value can anyone help me on that? 

2 ACCEPTED SOLUTIONS

@Burhan2 

share your BR condition and script you are using?

the new custom field is of type duration?

script should be something like this and BR should be Before Update

Ensure your BR triggers fine and the below script will work fine

    current.durationField2 = current.durationField1.dateNumericValue();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

Hi @Burhan2 ,

 

Use below code in your BR, it will work. I have tested it in PDI.

var gr = new GlideRecord('incident');
    if (gr.get(current.sys_id)) {

        current.u_business_duration = gr.business_duration;

    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

View solution in original post

9 REPLIES 9

Hi @Burhan2 ,

 

Use below code in your BR, it will work. I have tested it in PDI.

var gr = new GlideRecord('incident');
    if (gr.get(current.sys_id)) {

        current.u_business_duration = gr.business_duration;

    }

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Ankur Bawiskar
Tera Patron
Tera Patron

@Burhan2 

Any reason to hold same value in a custom field?

If you still require then you can use before update BR and ensure the condition is proper and set it via script OR Actions tab as shared by Runjay.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Doing it same way setting through actions but its not working

@Burhan2 

share your BR condition and script you are using?

the new custom field is of type duration?

script should be something like this and BR should be Before Update

Ensure your BR triggers fine and the below script will work fine

    current.durationField2 = current.durationField1.dateNumericValue();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Nilesh Wahule
Tera Guru

Hi @Burhan2 ,

Follow below Business rule:

NileshWahule_1-1735222005655.png

 

Then in advanced write below code.

NileshWahule_0-1735221960573.png

 

You can remove the condition if you want to always populate the field.

 

---------------------------------------------------------------------------------------------------

Please mark my answer as helpful/correct if it resolves your query.

Thanks,
Nilesh Wahule

---------------------------------------------------------------------------------------------------