Pop Up window to confirm and also used to update a record

SteveS
Kilo Expert

I am trying to create a script for Pop Up window to confirm and also used to update a record. Basically I want this script on the sc_task table to be an on submit so that it will pop up ok/cancel box and If they select ok, it will update a field on the sc_req_item (request Item) table. If they hit cancel, it will just perform the save/update function.

Since I am not very good at scripting, I have attempted a simple script but of course it does not seem to work or at least does not update the backordered field on the sc_req_item (request Item) table .

Ran on the sc_task table:



function onSubmit() {
var answer = confirm ("Does this need to be ordered? \n \n Click OK if this needs to be ordered \n \n Click Cancel if you do not need to order");
if (answer){
alert ("Order request has been sent to Purchasing.");
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.sys_id);
gr.query();
while(gr.next()) {
gr.backordered.setDisplayValue('true');
}
}
else{
alert ("Proceed to the next Task.");
// g_form.setValue ('current.sc_req_item.backordered, false');

}
}
2 REPLIES 2

SteveS
Kilo Expert

If its easier I would like to have a ordered required Yes/No field on the sc_task (Catalog task) table and when updated, it will updat the backordered box on the sc_req_item (Request Item) table.


SteveS
Kilo Expert

figured it out, now all i have to do is to make this also work if the user clicks the close task button.


function onSubmit() {

var desc = g_form.getValue('short_description');
var state = g_form.getValue('state');

if ((desc=='PC Accessory - Check Stock or Order from vendor') && (state=='3')){
var answer = confirm ("Does this need to be ordered? \n \n Click OK if this needs to be ordered \n \n Click Cancel if you do not need to order");
if (answer){
alert ("Order request has been sent to Purchasing.");
g_form.setValue('request_item.backordered', 'true');
// gsftSubmit(gel('sysverb_update_and_stay'));
//gsftSubmit(gel('sysverb_update'));

}
else{
// alert ("Proceed to the next Task.");
// g_form.setValue('u_backordered', 'false');
//gsftSubmit(gel('sysverb_update_and_stay'));
// g_form.setValue ('current.sc_req_item.backordered, false');

}
}
}