Service catalog - Client script works on the RITM form in the ITIL view but does not work on the portal and throws exception.

nss280
Kilo Contributor

Hi All,

I am just getting my hands dirty in servicenow development. I am facing an issue with the client script execution on the portal.

I have a business requirement to make the RITM variables in the catalog requested items read-only after submission. 
I have a client script that does makes the variables read-only. The script works for the ITIL view, however on the portal the get the below error

I have an OnLoad,  UItype=Al client script on the sc_req_item as below

function onLoad() {
//Type appropriate comment here, and begin script below
g_form.setVariablesReadOnly(true);
}

 

I get the below error on the portal when approver clicks the (i) beside the RITM and the RITM view opens up. The view is editable as well.

js_includes_sp.jsx?v=09-05-2018_1933&lp=Wed_Jan_02_11_47_43_PST_2019&c=5_49:66080 (g_env) [SCRIPT:EXEC] Error while running Client Script "Make Variable editor read only": TypeError: g_form.setVariablesReadOnly is not a function

 

Looking forward for any help.

 

Thanks in anticipation.

 

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

Set the UI type to Desktop which makes the script to run only in native view

setVariablesReadOnly is not supported in service portal

 

Edit: Below thread might be helpful

https://community.servicenow.com/community?id=community_question&sys_id=47204761db98dbc01dcaf3231f96...

View solution in original post

4 REPLIES 4

dvp
Mega Sage
Mega Sage

Set the UI type to Desktop which makes the script to run only in native view

setVariablesReadOnly is not supported in service portal

 

Edit: Below thread might be helpful

https://community.servicenow.com/community?id=community_question&sys_id=47204761db98dbc01dcaf3231f96...

nss280
Kilo Contributor

I Set the UI Type to read only and that worked. 

I am trying to understand the solution provided by tim2222. I am still learning the coding part. This one is pretty detailed.

Thank you dvp!

 

Luke Van Epen
Tera Guru

There are many Client script methods that work in Platform that dont work in the Portal. 

These links will help you find most of them:

Service Portal and client scripts | ServiceNow Docs

CMS to Service Portal transition (Scripts that are CMS only are also Platform only)

 

But when observing an error "g_form.someMethod is not a function" that means the Service Portal version of the g_form API doesnt recognise the method, and you need to use a different one. 

 

Really helpful Luke. Thank you