g_form.getUniqueValue() always returns same value in service catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 09:31 AM
I am adding an attachment to the SC item and I can see the sys id in the attachment table, and it does not match the sys_id that I am getting using 'g_form.getUniqueValue()'.
How do I get the actual id of the SC request ?
If I create the service catalog request 10 times, I always get the same sysid
The following code actually returns the sysid of the Record Producer in Service Portal, but I need sysid of the record ?
var sysid = g_form.getUniqueValue();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 09:36 AM
What is the use case you are trying to achieve with this?
You can access the sys_id of the record in the Producer script using current.sys_id.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 09:49 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 09:46 AM
@PriyaVerma A new record only gets created when the record producer form is submitted without any errors. You are getting the sys_id of the record producer in client script because the record has not yet created, this is by design.
If you wish to access the sys_id of the new record then it is only available in Server side record producer script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2024 10:05 AM
So how can I achieve my requirement. My reqt is to validate the validate the file type I am uploading in sys_attachment table. If type is valid then record will be submitted else system stops record submission.
In Record Producer, Catalog Client Script, I have written following code:
function onSubmit()
{
var ga = new GlideAjax('NGRPPortalUtilAjax'); // Call Script Incliude
var Sysid = g_form.getUniqueValue(); // sysid of the record
ga.addParam('sysparm_name', 'validateAttachment'); // call function
ga.addParam('sysparm_table_sys_id', Sysid);
ga.getXML(ValidateAttachment); // callback function
}
function ValidateAttachment(response)
{
var answerFromXML= response.responseXML.documentElement.getAttribute("answer");
var result = JSON.parse(answerFromXML);
alert(result);
if(result=='true')
{
alert('Valid Insert' + result);
}
else
{
alert("Please upload valid form
return false;
}
}
In Script Include, I need to the file I have uploaded in attachment table based on table_sys_id. If fiel type is ".jpg", return true. If file type is not ".jpg", returns false. But the problem here is how I can get table_sys_id ?