g_form.getUniqueValue() always returns same value in service catalog

PriyaVerma
Tera Contributor

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(); 

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

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.

I want to 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. So when I am trying to create sysid of the record using g_form.getUniqueValue() in client script, it does not match with table_sys_id of sys_attachment table. g_form.getUniqueValue() always return the same sysid, it return the sysid of Record Producer. Seems like this function does not work in Service Portal. 
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;
    }
}

Sandeep Rajput
Tera Patron
Tera Patron

@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.

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 ?