UI Builder - How do I get a value from the URL?

DrewW
Mega Sage
Mega Sage

I am using UI Builder to create a page with a custom setup.  When the page opens I need to know if its a new record connected to an existing parent.  I found that when I hit the new button I get the URL below which has the information that I want right after the "parentRecordSysId".  But I cannot seam to be able to get this value out of the URL.  Does anyone know how to go about this in UI Builder?

 

URL

./x/XXXXX/trr/record/x_XXXXX_trr_trr/25726d0d1b5c9258414a63166e4bcb2c/params/selected-tab-

index/2/sub/record/x_XXXXX_trr_letter/-1_uid_2/params/query/trr=25726d0d1b5c9258414a63166e4bcb2c/extra-params/query/trr=25726d0d1b5c9258414a63166e4bcb2c/parentTable/x_XXXXX_trr_trr/parentRecordSysId/25726d0d1b5c9258414a63166e4bcb2c

 

Things I have tried

Data Binding using

@context.props.parentRecordSysId

 

Client script

console.log(api.context.props.parentRecordSysId)

console.log(window)

but it displays undefined for both

 

Anyone have any idea's how I go about this?

 

4 REPLIES 4

Kevin83
ServiceNow Employee
ServiceNow Employee

It looks like you don't have a value for extra-params, or the value you posted isn't encoded right.

Usually I would expect the bit after extra-params to be encode, something like "query%2Ftrr%3D25726d0d1b5c9258414a63166e4bcb2c%2FparentTable%2Fx_XXXXX_trr_trr%2FparentRecordSysId%2F25726d0d1b5c9258414a63166e4bcb2c"

So what you would actually want is api.context.props.extraParams, and then you'd have to split on "/" and find the value for  parentRecordSysId in the those key value pairs


The URL I posted is strait from the URL line after I clicked the New button on a related list.  I replaced the instance name with a "." and changed the scope value but the rest is how the URL was.

 

I will check the "api.context.props.extraParams" and see what it has.

 

Kevin83
ServiceNow Employee
ServiceNow Employee

Interesting, seems a little suspect that the data after extraParams isn't encoded, that might be the source of the issues

Well then there is an issue with Workspaces that I have no access to fix.

 

On the note of extraParams I added a client script to run at Page ready and simply put

console.log(api.context.props.extraParams);
In it and got "undefined" as a result.
 
I even did
for(var i in api.context.props) {
    console.log(i);
    console.log(api.context.props[i]);
}

to be sure and nowhere in the returned values did I get anything that would allow me to get at a value in the URL path.

 

So that means I'm going to have to use an iFrame and a Service Portal Page/Widget to get this done.