- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 12:24 PM
Hello All,
I want to Abort(not let record submit) record submission through Record producer on Incident table if the selected
Configuration Item already exists with a particular incident. I have gone through same issues here but none of them were helpful. I have tried both catalog client onChange and onSubmit sctipt but none to avail.
Catalog onChange Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('global.checkCIExistIncident');
ga.addParam('sysparm_name', 'isCIAvailable');
ga.addParam('sysparm_ci',newValue);
//alert(g_form.getValue('cmdb_ci'));
//Tried only ga.getXML(submitRecord)
var myanswer = ga.getXML(submitRecord);
return myanswer;
function submitRecord(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
return answer;
}
}
Script include:
var checkCIExistIncident = Class.create();
checkCIExistIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isCIAvailable: function() {
var incGr = new GlideRecord('incident');
incGr.addQuery('cmdb_ci',this.getParameter('sysparm_ci'));
incGr.query();
gs.log('inside the ci check si');
if(incGr.next()){
return true;
}else{
return false;
}
},
type: 'checkCIExistIncident'
});
Any input in this regard will be greatly appreciated.
Thank you,
Mahesh.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 12:38 AM
Hi @maheshkhatal ,
I have tried simulating your issue in my PDI today and finally found the working code for your issue. Please try with the following Script Include and Client Script.
Script Include:
var checkCIExistIncident = Class.create();
checkCIExistIncident.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isCIAvailable: function() {
gs.info("MAK: Hello");
var incGr = new GlideRecord('incident');
incGr.addQuery('cmdb_ci', this.getParameter('sysparm_ci'));
incGr.addQuery('active', true);
incGr.query();
if (incGr.next()) {
return 'true';
} else {
return 'false';
}
},
type: 'checkCIExistIncident'
});
Client Script:
function onSubmit() {
if (g_scratchpad.isFormValidAjax) {
g_scratchpad.isFormValidAjax = null;
return true;
}
g_scratchpad.isFormValidAjax = false;
var cmdb_ci = g_form.getValue('cmdb_ci'); //change variable as per your configuration
var ga = new GlideAjax('global.checkCIExistIncident');
ga.addParam('sysparm_name', 'isCIAvailable');
ga.addParam('sysparm_ci', cmdb_ci);
ga.getXMLAnswer(setAnswer);
return false;
function setAnswer(answer) {
if (answer) {
if (answer == 'true') {
g_form.addErrorMessage("There is an Incidnet for this CI");
return false;
} else {
var actionName = g_form.getActionName();
g_scratchpad.isFormValidAjax = true;
g_form.submit(actionName);
}
}
}
}
Please mark my answer helpful and accept as solution if it worked for you 👍✔️
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 05:44 AM
Hello Anvesh,
First of all thanks to your unwavering dedication to get my doubt resolved. Since it worked on your PDI it should have worked on mine as well but it is not the case(I copy pasted your code-to be on sure side). That g_scratchpad I had tried yesterday. Today when I kept UI Type as 'All' or 'Mobile' it is letting me submit the record. But when I kept 'Desktop' it gave me an error g_scratchpad is not defined.
FYI, I am using Utah version and providing you with the following configuration details for the same.
Error: when Desktop is option=>Error MessageonSubmit script error: ReferenceError: g_scratchpad is not defined:
function () { [native code] }
Else it goes on submitting the code.
Thank you once again.
Mahesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 06:21 AM
Are you using this Record Producer in Platform UI or Service Portal? Or Both ?
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 07:40 AM
Hi @AnveshKumar M ,
This time tested from Service Portal. It worked. May be I should have tried earlier. It's bit weird. Thanks though.
Mahesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2023 09:02 AM
It worked when I submitted from Service Portal. Thank you again.