- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 03:52 AM
Hi Team ,
am using the client script in UI action and trying to submit the for after filling the data ,but form is not saved or submitted
function getDetails() {
var v_displayRef = g_form.getReference('display_name');
var referencedSysId = g_form.getValue('display_name');
var assetID = referencedSysId;
var getValues = new GlideAjax('x_cenv_api_hbm_ton.FetchAdditionalDetails');
getValues.addParam('sysparm_name', 'GetDetailsAPI');
getValues.addParam('sysparm_asset', assetID);
getValues.getXML(getResponse)
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var formatJSON = JSON.parse(answer);
g_form.setValue('u_stock', formatJSON.Stock);
g_form.submit();
action.setRedirectURL(current);
}
Please guide me
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 04:02 AM
Hi @String
I think you need to correct the script , thats not how its done.
make sure of above highlighted areas
here is the script:
function getDetails() {
var v_displayRef = g_form.getReference('display_name');
var referencedSysId = g_form.getValue('display_name');
var assetID = referencedSysId;
var getValues = new GlideAjax('x_cenv_api_hbm_ton.FetchAdditionalDetails');
getValues.addParam('sysparm_name', 'GetDetailsAPI');
getValues.addParam('sysparm_asset', assetID);
getValues.getXML(getResponse);
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var formatJSON = JSON.parse(answer);
g_form.setValue('u_stock', formatJSON.Stock);
gsftSubmit(null, g_form.getFormElement(), "getDetailsAction");
}
}
if (typeof window == 'undefined')
setRedirect();
function setRedirect() {
current.update();
action.setRedirectURL(current);
}
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 05:28 AM
try this once
function getDetails() {
var v_displayRef = g_form.getReference('display_name');
var referencedSysId = g_form.getValue('display_name');
var loadingDialog = new GlideDialogWindow('load_meter', true);
//loadingDialog.setPreference('table', 'loading');
loadingDialog.setTitle('Please wait..');
loadingDialog.setSize(400, 200);
loadingDialog.render();
var assetID = referencedSysId;
var getValues = new GlideAjax('x_cenv_api_hbm_ton.FetchAdditionalDetails'); //Calling Script Include.
getValues.addParam('sysparm_name', 'GetDetailsAPI'); // Function name of the script include.
getValues.addParam('sysparm_asset', assetID);
getValues.getXML(getResponse.bind({
dialog: loadingDialog
}));
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != 500) {
try {
var formatJSON = JSON.parse(answer);
if (g_form.getValue('u_date_since_last_heart_beat') == formatJSON.DaysSinceLastHB && g_form.getValue('u_last_communicaton_date') == formatJSON.LastComDate && g_form.getValue('u_stock_location_id') == formatJSON.StockLocationId && g_form.getValue('u_stock_location_name') == formatJSON.StockLocationName && g_form.getValue('u_toner_enabled') == formatJSON.TonerEnabledFlag.toLowerCase()) {
this.dialog.destroy();
g_form.addInfoMessage("No new updates on Additional Details ");
//gsftSubmit(null, g_form.getFormElement(), "getDetailsAction");
} else {
g_form.setValue('u_date_since_last_heart_beat', formatJSON.DaysSinceLastHB);
g_form.setValue('u_last_communicaton_date', formatJSON.LastComDate);
g_form.setValue('u_toner_enabled', formatJSON.TonerEnabledFlag);
if (formatJSON.StockLocationId != undefined) {
g_form.setValue('u_stock_location_id', formatJSON.StockLocationId);
}
if (formatJSON.StockLocationName != undefined) {
g_form.setValue('u_stock_location_name', formatJSON.StockLocationName);
}
this.dialog.destroy();
g_form.addInfoMessage("Below fileds are updated ");
g_form.save();
}
} catch (error) {
this.dialog.destroy();
g_form.addErrorMessage("Error occurred, please try after some time.", error);
}
} else {
this.dialog.destroy();
g_form.addErrorMessage('Error occurred, please try after some time');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-27-2023 05:09 AM
can you share complete script?
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-27-2023 05:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 05:23 AM
@String remove g_form.addInfoMessage("Below fileds are updated ");
line above gsftSubmit().
and add it in setRedirect()
function setRedirect() {
current.update();
gs.addInfoMessage('Below fileds are updated');
action.setRedirectURL(current);
}
Regards,Sushant Malsure
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2023 05:28 AM
try this once
function getDetails() {
var v_displayRef = g_form.getReference('display_name');
var referencedSysId = g_form.getValue('display_name');
var loadingDialog = new GlideDialogWindow('load_meter', true);
//loadingDialog.setPreference('table', 'loading');
loadingDialog.setTitle('Please wait..');
loadingDialog.setSize(400, 200);
loadingDialog.render();
var assetID = referencedSysId;
var getValues = new GlideAjax('x_cenv_api_hbm_ton.FetchAdditionalDetails'); //Calling Script Include.
getValues.addParam('sysparm_name', 'GetDetailsAPI'); // Function name of the script include.
getValues.addParam('sysparm_asset', assetID);
getValues.getXML(getResponse.bind({
dialog: loadingDialog
}));
}
function getResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer != 500) {
try {
var formatJSON = JSON.parse(answer);
if (g_form.getValue('u_date_since_last_heart_beat') == formatJSON.DaysSinceLastHB && g_form.getValue('u_last_communicaton_date') == formatJSON.LastComDate && g_form.getValue('u_stock_location_id') == formatJSON.StockLocationId && g_form.getValue('u_stock_location_name') == formatJSON.StockLocationName && g_form.getValue('u_toner_enabled') == formatJSON.TonerEnabledFlag.toLowerCase()) {
this.dialog.destroy();
g_form.addInfoMessage("No new updates on Additional Details ");
//gsftSubmit(null, g_form.getFormElement(), "getDetailsAction");
} else {
g_form.setValue('u_date_since_last_heart_beat', formatJSON.DaysSinceLastHB);
g_form.setValue('u_last_communicaton_date', formatJSON.LastComDate);
g_form.setValue('u_toner_enabled', formatJSON.TonerEnabledFlag);
if (formatJSON.StockLocationId != undefined) {
g_form.setValue('u_stock_location_id', formatJSON.StockLocationId);
}
if (formatJSON.StockLocationName != undefined) {
g_form.setValue('u_stock_location_name', formatJSON.StockLocationName);
}
this.dialog.destroy();
g_form.addInfoMessage("Below fileds are updated ");
g_form.save();
}
} catch (error) {
this.dialog.destroy();
g_form.addErrorMessage("Error occurred, please try after some time.", error);
}
} else {
this.dialog.destroy();
g_form.addErrorMessage('Error occurred, please try after some time');
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-30-2023 10:28 PM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader