Use Tenant ID in translation script or request script for rest option

Hi, I have an option list created with a REST call to ServiceNow. I need to filter the values returned on the tenantId base. I have two ways, create a dynamic rest call changing the query parameter or querying all the data and filtering them in morpheus using the translation script. In both cases I need to access the current tenantId value but it seems no possible. Is there any solution to this? Thanks

you can obtain the current tenant/account id in the translation script with the following variable:

input.accountId; //accountId is builtin variable so you are not required to create this input in the UI

Hi wabbas, I tried it but it seem not to work, This is the code in translation script:

results = ;
for (let i=0; i < data.result.length; i++){
results.push({name: String(input.accountId), value:data.result[i].name})
}
I put accountId in name to see the value but I obtain an undefined value

Are you trying to pass accountId of the current executing user to filter the list? Or view the accountId value from your REST call? You seem to have merged the two concepts together.

Seems like you want to add a where argument in your translation script to filter based on the current user’s accountId. Instead you are trying to hardcode the user’s tenantId as the name value for all options. Or in a Request script you can filter the payload prior to the return similar to this thread.

Hi, I am trying to filter the result on the tenantID of the current user. I changed The translation script in this way:

results = ;
for (let i=0; i < data.result.length; i++){
if (data.result[i].u_tenant_morpheus == input.accountId) {
results.push({name: data.result[i].name, value:data.result[i].u_tenant_morpheus});
}}

but it returns no rows

But if I change it inserting a static string like this

results = ;
for (let i=0; i < data.result.length; i++){
if (data.result[i].u_tenant_morpheus == “2”) {
results.push({name: data.result[i].name, value:data.result[i].u_tenant_morpheus});
}}

it returns the expected rows.

In the image I assigned the value of input.accountId to the name of the option list to see if it was correctly read.

I have solved using this:

results = ;

for (let i=0; i < data.result.length; i++){
if (data.result[i].u_tenant_morpheus) {
if (data.result[i].u_tenant_morpheus == input.accountId) {
results.push({name:data.result[i].name, value:data.result[i].name});
}}}

and setting the flag “real time” in rest options

1 Like