Script Action - Set field value?

Edwin Fuller
Tera Guru

I need to have a script action set a fields value "current_status" to a specific value "Complete - Auto Closed". Can anyone let me know how this can be written?

Thanks so much,

Edwin

1 ACCEPTED SOLUTION

Hi Edwin,



Your scheduled script looks fine as per screen shot. However the code you pasted, does not have correct syntax for gs.eventQueue() function in schedule script.



In your script action just do this:



closeRecord();



function closeRecord() {


current.current_status = 'Complete - AutoClosed';


current.update();


}


View solution in original post

6 REPLIES 6

Bharath40
Giga Guru

Script action should be triggered by a Event, you may have to pass the parameters. Glide the table and update the field.



Can you please elaborate the scenario so that I can provide you exact solution, because this can be done in many ways .



Thanks,


I'm trying to close records that are in a particular status of "Requestor to Complete" and have not been updated for 48 hours. So I've written a scheduled Script that triggers an event. That event is used to trigger the script action. Below are screen shots of everything




This script below could potentially be written better, but it's what I've came up with since I'm fairly new to scripting. I only want to close records where the "audience" field is equal to 'Internal' and the status is equal to "Requestor to Complete" and the record has not been updated for 48 hours. The script below is excluding everything to only get me the condition I just described.


find_real_file.png


var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.addEncodedQuery('sys_updated_on>javascript:gs.daysAgoStart(2)');


gr.addQuery('audience','!=','Client');


gr.addQuery('audience','!=','Other');


gr.addQuery('current_status','!=','Complete');


gr.addQuery('current_status','!=','Requestor Canceled');


gr.addQuery('current_status','!=','Closed-CCCU Reported');


gr.addQuery('current_status','!=','Clarification Needed');


gr.addQuery('current_status','!=','Draft');


gr.addQuery('current_status','!=','Acknowledged');


gr.addQuery('current_status','!=','In Progress');


gr.addQuery('current_status','!=','Client Request Not Met');


gr.addQuery('current_status','!=','Rebuttal Submitted');


gr.addQuery('current_status','!=','Rebuttal Rejected');


gr.addQuery('current_status','!=','New');


gr.query();


while(gr.next()){


gs.eventQueue('x_hemas_connectus2.closeinternal');


}




find_real_file.png


find_real_file.png


closeRecord();




function closeRecord() {


var gr = new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


  current.current_status = 'Complete - AutoClosed';


}


You have to pass parameters when you call an event



Scheduled Job Script:



var gr= new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr.addEncodedQuery('sys_updated_on>javascript:gs.daysAgoStart(2)');


gr.addQuery('audience','!=','Client');


gr.addQuery('audience','!=','Other');


gr.addQuery('current_status','!=','Complete');


gr.addQuery('current_status','!=','Requestor Canceled');


gr.addQuery('current_status','!=','Closed-CCCU Reported');


gr.addQuery('current_status','!=','Clarification Needed');


gr.addQuery('current_status','!=','Draft');


gr.addQuery('current_status','!=','Acknowledged');


gr.addQuery('current_status','!=','In Progress');


gr.addQuery('current_status','!=','Client Request Not Met');


gr.addQuery('current_status','!=','Rebuttal Submitted');


gr.addQuery('current_status','!=','Rebuttal Rejected');


gr.addQuery('current_status','!=','New');


gr.query();


while(gr.next()){


gs.eventQueue('x_hemas_connectus2.closeinternal',gr,gr);


}




Script action:



closeRecord();


function closeRecord() {


var gr1 = new GlideRecord("x_hemas_connectus2_x_hemas_connectus_connectus");


gr1.get(event.param1.sys_id);


if(gr1.next()){


  gr1.current_status = 'Complete - AutoClosed';


  gr1.update();


}


}



P.S Mark Correct, Hit Like/Helpful if you think my answer is worthy.



Thanks,


Hi Edwin,



Your scheduled script looks fine as per screen shot. However the code you pasted, does not have correct syntax for gs.eventQueue() function in schedule script.



In your script action just do this:



closeRecord();



function closeRecord() {


current.current_status = 'Complete - AutoClosed';


current.update();


}