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

$sp.getRecord does not work in scoped application . servicenow bug ??

newhand
Mega Sage

Hi everyone.

 

I'm sucked in below problem.

If i put this code into a scoped portal widget's servier side script ,  the script will stop at line2 ($sp.gerRecord) without any errors or warnnings...

But if i put it into a global widget , everything goes well ...I don't know why...

gs.info('yyyyyyy ' + data.table + data.sys_id);

var rec = $sp.getRecord('sc_req_item', 'ccbaa13c47ea8e10ea269dbe316d43f8');

gs.info("xxxxx")

 

Please mark my answer as correct and helpful based on Impact.
5 REPLIES 5

Rajesh Chopade1
Mega Sage

Hi @newhand 

 

"getRecord", not supported in scoped app.

please query the sc_req_item table with sysId and get the catalog record.

 

Thank you

 

Community Alums
Not applicable

Hi @newhand ,

In scoped application $sp.getRecord will not work you can use below script

var gr = new GlideRecord('sc_req_item');
if(gr.get('ccbaa13c47ea8e10ea269dbe316d43f8')){
	gs.info("xxxxx");
}

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

dgarad
Giga Sage

Hi @newhand 

Refer to the below link.

https://serviceportal.io/docs/documentation/widget_server_script_apis.md

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

newhand
Mega Sage

@Community Alums @Rajesh Chopade1 
Finally , I caught the error with try-catch。

Yes,as the error message says, getRecord is not supported in scoped application。 

But according to the official document below,it should be supported in the scoped application。。。

And I also found an OOTB widget in the scoped application using getRecord (I'm not sure if it works...)。

newhand_0-1718068756872.png

newhand_1-1718069118932.png

 

 

Please mark my answer as correct and helpful based on Impact.