- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 07:02 AM
Hi,
I am trying to clone a task through ui action.
However, the gsft submit code is not working.
Here is my code:
//Client-side
var st = g_form.getValue('state');
if (st == 18) {
var sysID = g_form.getUniqueValue();
var ga = new GlideAjax('ValidateCloseIncomplete');
ga.addParam('sysparm_name', 'checkQuestions');
ga.addParam('sysparm_sysid', sysID);
ga.getXMLWait();
var answer = ga.getAnswer();
alert('Answer: ' + answer + 'sys id: ' + sysID);
}
//Call the UI Action
if (answer == 'true') {
alert('Answer gsft : ' + answer);
gsftSubmit(null, g_form.getFormElement(), 'close_incomplete'); //MUST call the 'Action name' set in this UI Action
} else {
gs.addInfoMessage('Please, fill all the questionnaires before closing the task.');
}
//Server-side
if (typeof window == 'undefined')
runServerCode();
//Server-side function
function runServerCode() {
var clone = new SMTask().cloneTask(current);
(new StateFlow().processFlow(current, '41dfa2e0d7630100fceaa6859e61035d', 'manual'));
gs.addInfoMessage(gs.getMessage("Cloned from {0}", current.number));
action.setRedirectURL(clone);
}
}
The server side code is not working.
Thanks
Kevin
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 07:25 AM
Hi Kevin,
there are few corrections in your script
1) ensure the UI action action name is 'close_incomplete' as that is present in gsft call; if that name is incorrect it won't go to server side
2) gs won't work in client side
3) I assume cloneTask() is the function name for Onclick
4) also the Onclick function should end before typeof window
Updated script below:
function cloneTask(){
//Client-side
var st = g_form.getValue('state');
if (st == 18) {
var sysID = g_form.getUniqueValue();
var ga = new GlideAjax('ValidateCloseIncomplete');
ga.addParam('sysparm_name', 'checkQuestions');
ga.addParam('sysparm_sysid', sysID);
ga.getXMLWait();
var answer = ga.getAnswer();
alert('Answer: ' + answer + 'sys id: ' + sysID);
//Call the UI Action
if (answer == 'true') {
alert('Answer gsft : ' + answer);
gsftSubmit(null, g_form.getFormElement(), 'close_incomplete'); //MUST call the 'Action name' set in this UI Action
} else {
alert('Please, fill all the questionnaires before closing the task.');
return;
}
}
// function ends here
}
//Server-side
if (typeof window == 'undefined')
runServerCode();
//Server-side function
function runServerCode() {
var clone = new SMTask().cloneTask(current);
(new StateFlow().processFlow(current, '41dfa2e0d7630100fceaa6859e61035d', 'manual'));
gs.addInfoMessage(gs.getMessage("Cloned from {0}", current.number));
action.setRedirectURL(clone);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 07:40 AM
Worked Like a charm.
Ankur to the rescue again.
Thanks Ankur, really appreciate it.
I was writing the server side code withing the function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 08:00 AM
You are welcome.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 07:21 AM
Hello,
Try replacing the Client code within blocks like -
function onClickClientCode(){
if (answer == 'true'){
alert('Answer gsft : ' + answer);
gsftSubmit(null, g_form.getFormElement(), 'close_incomplete'); //MUST call the 'Action name' set in this UI Action
}
else{
gs.addInfoMessage('Please, fill all the questionnaires before closing the task.');
}
}
The gsftSubmit calls the Server side only if the 'If' condition turns to be true. Else, there is no server-call happening. Make sure you populate On click field on UI Action with the function name - here onClickClientCode(). Hope this helps.
Regards, Akash
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-14-2020 07:25 AM
Hi Akash,
I have created a function and used the same in UI Action's On click field.
The problem is with the server side.
Thanks