The CreatorCon Call for Content is officially open! Get started here.

is there and equivalent of "g_form.getElement('sysparm_item_guid').value" in the portal ?

poyntzj
Kilo Sage

Looking to revise one of my old Client Scripts which depends on checking a record while the user is in a catalog item

In the old CMS I would use  g_form.getElement('sysparm_item_guid').value which obviously fails in the Portal, but wondered if there is an equivalent I can use

I can see the Catalog Item is already assigned a new sys_id in the instance, but I cannot find how to access this Id from the portal.

 

Any ideas ?

 

TIA

24 REPLIES 24

But how do I get the sys_id from the onSubmit client script ?

The code is running as on onSubmit

@poyntzj 

you can use onSubmit client script with Synchronous ajax

Query sys_attachment and orderbydescending and then use ExcelParser to check the header and content

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

OK.  My code is already synchronous Ajax calling a Script include and is an onSubmit Script

It is already querying sys_attachment, however, to Query the sys_attachment table I need the sys_id so I can perform the query

It is how I get this sys_id that is eluding me when running via the portal.

@poyntzj 

If somehow you get the cart item sys_id that will work

or as of now do this

var gr = new GlideRecord("sys_attachment");
    gr.addEncodedQuery("table_name=sc_cart_item");
    gr.orderByDesc("sys_created_on");

    gr.setLimit(1);
    gr.query();

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Won't necesaarily help on a busy instance

In the debugger, as the page loads you see this entries

find_real_file.png

 

the sys_id in the int sys_attachment? line is the sys_id that will be used in the sys_attachment table - its there - somewhere da8c70e62fe930903c345fd62799b6cc

After the form has loaded, if I now add an attachment with that same sys_id

find_real_file.png