- 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:17 AM
Hi Kevin,
Not sure if you are using the first line with a function name that results in On-Click action on Client Side - Example:
function clientOnClickFn(){
//code here
//Add gsftSubmit line within this function
gsftSubmit(null, g_form.getFormElement(), '<Action_name>');
//Action_name is your Aciton field on UI ACtion
}
Provide the clientOnClickFn on the OnClick field on UI Action. Also, the gsftSubmit must be within your Client side On-click function.
Refer for details - client-server-code-ui-action
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:20 AM
Hi Kevin,
Are you sure the client side code executed fine and server side code executed? the info message came?
Is the redirection not working?
Also did you use proper onclick function name in script
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:23 AM
Hi Ankur,
I am able to get this alert: alert('Answer gsft : ' + answer);
The server side is not working.
Thanks
- 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