Adding a closure template

Rob Bushrod
Tera Guru

I have been asked if it is possible to add a closure template for a specific contract within our system.

We look after a lot of contracts in our system and I for one they would like to know it there is a way of setting up a template that is applied when the resolver team are closing their subtask.

The template that will be applied is a list of questions that need to be answered by the resolver, so my idea is that when the resolver hits 'Resolve' then the closure notes section pre-populates with this list of questions that need to be answered.

This would require amending the UI Action for 'Resolve' but I am worried that this would open up the possibility of this becoming unmanageable if other contracts desired this as well. Also not sure exactly how I would write this into the existing code.

As anybody had to do this before and what approach did you take?

Thanks,

Rob

1 ACCEPTED SOLUTION

Rob Bushrod
Tera Guru

This was resolved by using the following code and creating a system property with the template as it will be easier to maintain and edit if required.



TUgetTimeCard();


function TUgetTimeCard() {


var offsiteQuestions = gs.getProperty('ua.offsite_template'); //Add the string name of the property


var vSiteVisit = new GlideRecord('u_site_visit');


vSiteVisit.addQuery ('u_task', current.sys_id);


vSiteVisit.addQuery ('u_active' , true); //safety net


vSiteVisit.query();


if (vSiteVisit.next()) {


gs.addInfoMessage (gs.getMessage('Work finish time for time card ' + vSiteVisit.u_number + ' set to ' + gs.nowDateTime()));


gs.addInfoMessage (gs.getMessage('Please provide Visit Summary'));


vSiteVisit.u_summary = offsiteQuestions;


vSiteVisit.update();


var now = gs.nowDateTime();


var vTimeCard = 'u_site_visit.do?sys_id=' + vSiteVisit.sys_id + '&sysparm_workfinish=' + now;


action.setRedirectURL(vTimeCard);


action.setReturnURL(current);


} else {


//error cant find time card


gs.addErrorMessage (gs.getMessage ('**ERROR - Unable to locate an active Site Visit card for ' + gs.getUserName() + ' for this task. Please contact a System Administrator.'));


return false;


}


}


View solution in original post

4 REPLIES 4

johnolivermendo
ServiceNow Employee
ServiceNow Employee

Hey Rob,



Maybe something like this would work for you. Below you'll see the following changes:


  1. I did an 'Insert and Stay' on the original Resolve UI Action.
  2. Changed the name
  3. added a condition checking if the current form you're on is the specific contract you want
    • I'm assuming it's a field on your incident table
    • Note: the condition field decides when this UI button will appear on the form. If you don't want both the original Resolve button and the Resolve Specific Contract button to appear, then also add the opposite condition on your 'Resolve' UI Action (current.CONTRACT_FIELD != 'SPECIFIC CONTRACT'
  4. Created a string variable to hold all of your closure questions
    • Keep in mind that you need to concatenate each questions and add '/n' to add more spacing between the questions
  5. g_form.setValue('close_notes' closureQuestions)
    • This adds the questions to the closure field
    • You might also want to set your close_code field since that is also mandatory when you set the incident to resolve

Screen Shot 2017-04-21 at 2.29.10 PM.JPG



Everything else should be the same. Let me know if this works. Thanks!


Hi John,



Thank you for your reply but it has now been decided that the template is going to be set when an engineer comes offsite.



I can get the button onto the form


find_real_file.png


But I'm struggling to get the questions to go into the field that I need them in and in fact whenever I have the g_form.setValue line included I get taken back to the previous page


find_real_file.png



not the offsite page, where I want to be directed to and place the questions into the Summary field


find_real_file.png


If you can provide anymore assistance I would appreciate it?



Thanks,



Rob


Hi John,



Did you manage to look at what I sent over as I am still having issues getting this created. It dropped off the radar a bit but have got some time to pick it up again.



Thanks,



Rob


Rob Bushrod
Tera Guru

This was resolved by using the following code and creating a system property with the template as it will be easier to maintain and edit if required.



TUgetTimeCard();


function TUgetTimeCard() {


var offsiteQuestions = gs.getProperty('ua.offsite_template'); //Add the string name of the property


var vSiteVisit = new GlideRecord('u_site_visit');


vSiteVisit.addQuery ('u_task', current.sys_id);


vSiteVisit.addQuery ('u_active' , true); //safety net


vSiteVisit.query();


if (vSiteVisit.next()) {


gs.addInfoMessage (gs.getMessage('Work finish time for time card ' + vSiteVisit.u_number + ' set to ' + gs.nowDateTime()));


gs.addInfoMessage (gs.getMessage('Please provide Visit Summary'));


vSiteVisit.u_summary = offsiteQuestions;


vSiteVisit.update();


var now = gs.nowDateTime();


var vTimeCard = 'u_site_visit.do?sys_id=' + vSiteVisit.sys_id + '&sysparm_workfinish=' + now;


action.setRedirectURL(vTimeCard);


action.setReturnURL(current);


} else {


//error cant find time card


gs.addErrorMessage (gs.getMessage ('**ERROR - Unable to locate an active Site Visit card for ' + gs.getUserName() + ' for this task. Please contact a System Administrator.'));


return false;


}


}