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

You would need to get the relationship object, evaluate the query_with field, against the target and apply_to records.

if (data.relationship_id) {
		var rel = new GlideRecord('sys_relationship');
		if (rel.get(data.relationship_id.slice(4))) {
			var target = new GlideRecord(data.table);
			var applyTo = new GlideRecord(data.apply_to);
			applyTo.get("sys_id", data.apply_to_sys_id);
			
			var query_with = rel.getValue('query_with');
			var eval = new GlideScopedEvaluator()
			var evalVars = {'current': target, 'parent': applyTo};
			eval.evaluateScript(rel, 'query_with', evalVars);
			target = eval.getVariable('current');
			
			data.exportQuery = target.getEncodedQuery();
			gr.addEncodedQuery(data.exportQuery);
		}
	}

 

-O-
Kilo Patron
Kilo Patron

If this is not meant to be posted on Store, you can create a Script Include in global scope, marked as Accessible from All application scopes and call that Script Include from scope. The Script Include method in which you will use GlideRelationship must return a primitive (e.g. string, number, boolean) or a scope compatible object - pure JavaScript objects that contain properties with primitive values.