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

mike275
Mega Expert

I'm using `g_form.getUniqueValue()` from a service catalog's onSubmit method and it always returns the same ID which is not a valid one.

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 get from `g_form.getUniqueValue()`.

In fact, every time I create a new SC request I get the same value for ``g_form.getUniqueValue()`.

How do I get the actual id of the SC request I'm making?

In the below code, if I create the service catalog request 20 times, I always get the same sysid

function onSubmit() {
var sysid = g_form.getUniqueValue();
// var attach = new GlideRecord('sys_attachment');
// attach.addQuery('table_sys_id',sysid);
// attach.query();
// if(attach.next()){
// alert("form contains attachment for " + sysid);
// } else {
// alert("No attachment for " + sysid);
// }

var shouldHaveAttachment = g_form.getValue("use_spreadsheet") === "true";
alert("Submitting " + sysid + " : false for now - expecting spreadsheet: " + shouldHaveAttachment);

return true;
}

1 ACCEPTED SOLUTION

mike275
Mega Expert

I get the same ID all the time, I looked at the DOM and found hidden values, and either of them work:

sysparm_attachment_cart_id or sysparm_item_guid - so the code is g_form.getParameter('sysparm_attachment_cart_id');

View solution in original post

4 REPLIES 4

Elijah Aromola
Mega Sage

That should return the sys_id. You could try :

g_form.getParameter('sysparm_id')

It returns the same value as the method I'm calling, I'm afraid:

 

find_real_file.png

I've even tried creating a catalog request in a different browser and it returns the same number.

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,


YOu want id of the request or the catalog item?


BEcause you have script on catalog item, so it will always give you same sys_id.


Thanks,
Ashutosh

mike275
Mega Expert

I get the same ID all the time, I looked at the DOM and found hidden values, and either of them work:

sysparm_attachment_cart_id or sysparm_item_guid - so the code is g_form.getParameter('sysparm_attachment_cart_id');