GlideRelationship is not working in scoped application

Sivakumar10
Tera Contributor

Hi Team,

I have cloned the OOB Data table widget in a scoped application, while doing the same I am gettting error "GlideRelationship is not working in scoped application" below is the snipped of code where this has been used.


if (data.relationship_id) {
var rel = GlideRelationship.get(data.relationship_id);
var target = new GlideRecord(data.table);
var applyTo = new GlideRecord(data.apply_to);
applyTo.get("sys_id", data.apply_to_sys_id);
rel.queryWith(applyTo, target); // put the relationship query into target
data.exportQuery = target.getEncodedQuery();
grRecord.addEncodedQuery(data.exportQuery); // get the query the relationship made for us
}

Kindly request to provide me a suggestion or a way where we can use the same in scoped application.

TIA

Regards,
Sivakumar M

6 REPLIES 6

Sai Shravan
Mega Sage

Hi @Sivakumar10 ,


The GlideRelationship class is not available in scoped applications due to security restrictions. However, you can still implement relationship-based filtering using GlideRecord in a scoped application.

if (data.relationship_id) {
  var rel = new GlideRecord('sys_db_object_relation');
  rel.addQuery('child_table', data.table);
  rel.addQuery('parent_table', data.apply_to);
  rel.query();

  var target = new GlideRecord(data.table);
  var applyTo = new GlideRecord(data.apply_to);
  applyTo.get("sys_id", data.apply_to_sys_id);
  target.addQuery('sys_id', rel.getElement('parent') + '=' + applyTo.getUniqueValue());

  data.exportQuery = target.getEncodedQuery();
  grRecord.addEncodedQuery(data.exportQuery);
}

 

Can you give it a try with the above code.

Regards,
Shravan.
Please mark it as helpful if this helps you 🙂 

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hi @Sai Shravan ,

Thanks for the response.
While trying the mentioned script, I am not able to glide 'sys_db_object_relation' table as it is not available in the system.
Could you please suggest on the same.

TIA

Hi @Sivakumar10 ,

I apologize for the mistake. It is sys_relationship 

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

Hi @Sai Shravan 

No worries tried that as well. It is not listing the related records it just shows no record message.
I think this script is not querying the records.

TIA