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

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on
9 REPLIES 9

Runjay Patel
Giga Sage

Hi @Burhan2 ,

 

You can achieve it using before update BR.

RunjayPatel_0-1735219671784.png

 

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

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

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

 

Part 2. In this video i have talked about overview on ServiceNow platform/tool. How you can opt for personal dev instance (PDI)? how to login in ServiceNow instance and navigation to OOB modules. For document please visit: https://servicenowwithrunjay.com/ Follow Facebook page for latest update on

I tried exactly same this with my field but its not working when incident gets resolved the business duration field gets filled but my custom field is still empty

Hi @Burhan2 ,

 

I guess, the field type is not same for both the fields, can you check the type of field in the dictionary for both "Business Duration" and your custom field?

 

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

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

Thanks,
Nilesh Wahule

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



Yes type is 'duration' for both the fields