Validation on catalog variables
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 01:34 AM
Hi, I am new here and new to ServiceNow.
I am currently learning flow designer and have a question about validation on a Catalog variable.
I have created a Catalog item that has a flow process engine. The Catalog item collects data for new services in the cmdb_ci_service table. The Catalog item uses a multi-row variable set and checks to ensure that each row added has a unique value before adding the row on the Catalog item form.
Upon submission the flow triggers an approval and when approved it loops through each item and creates a record in the cmdb_ci_service table having first checked that the service name does not already exists.
This works fine; however, the requester would have no idea which service(s) were not created (if they already existed) until we check the submission and then inform them.
Does anyone know if there is a way to add validation to a variable on a form where the variable type is ‘Single Line Text’ or perhaps another variable type? E.g., kind of like a reference variable but in reverse, i.e., if the value is not found in the referencing table then allow the value to be entered into the field on the Catalog form.
I hope I am making sense.
Many thanks
Maxine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 06:17 AM
Yes, You can use onchage client script and Glide Ajax to validate the field.
Below are the sample scripts :
var service = g_form.getValue('your variable name');
var ajax = new GlideAjax('checkForService');
ajax.addParam('sysparm_name', 'getDetails'); // function name
ajax.addParam('sysparm_variable', service); // user
ajax.getXML(ServiceParse); // call back function
function ServiceParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var service= JSON.parse(answer); // parse response
if(service == "true")
{
g_form.clearValue("variable name");
}
}
Below is sample client callable script include :
getDetails : function() {
var Service= this.getParameter('sysparm_variable');
var GR = new GlideRecord('cmdb_ci_service');
GR.addQuery('sys_id', Service);
GR.query();
if (GR.next()) {
return true;
}
else{
return false;
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:39 PM
Thank you, I will give this a try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2023 01:50 AM
Hi Mehta, kind of. I was just working on it when you messaged. As I am new to ServiceNow and even newer to JavaScript, so I did it a slightly different way so I could understanding my logic.
I created a 'catalog client script' that runs for the variable in question upon 'onChange'
The script includes that it calls looks like this
It is working. However, although the script stops duplicate services with the same name from being created, when I create a service with the same name directly in cmdb_ci_service, it allows it to create. I thought business rule 'Check service name uniqueness' was suppose to avoid this.
Many thanks
Max
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 01:16 AM
Yes,
As per the code in the business rule, if the name matches then it will restrict from inserting the record.
This is Case Sensitive and even a space will allowed to insert the record.
Can you please marked it as correct answer or helpful. If it solved your query.