What is the use of setWorkFlow(false)? Scoped GlideRecord - setWorkflow(Boolean enable) Enables or disables the running of business rules, script engines, and audit.

mayanknayak
Tera Contributor

If setWorkFlow(false) disable all business rule run after it. Then why we create those business rule which runs after it.

6 REPLIES 6

Peter de Bock1
Mega Guru

hi,

Just for your information about using setworkflow in a scoped application;

Today I faced exactly the same issue "Access to api 'setWorkflow' has been refused due to the api's cross-scope access policy."

After analyzing I found the root cause and a solution for it. The root cause is that this function 'setWorkflow' is not supported in a scoped application. I doubt that it is feasible to allow this by configuring a cross scoped privilege as it is not an object (table, script include, ...).

To resolve it, you can create a new script Include in the global scope with a function which has the query and the setWorkflow in it. Then return your response. The setWorkflow can be used to disable Business Rules for Updates, Deletes and Inserts, though also so to circumvent Business Rule Before queries.

The setWorkflow is working 100% in a global scope script include 🙂

 

Example call:

var glSI = new global.your-global-script-include();
var responseObject = glSI.your-function();

 

Please mark helpfull or answered when when it does 🙂

 

regards, Peter

Peter de Bock1
Mega Guru

I have pasted two examples:

 

Example A: An example to avoid business rule before queries in a script include in the same scope as the object, can be done as follow:

Get a Hr Profile record in a "Human Resources: Core" scope script include

//get the hr profile based on unique key "intuserid"
var hrProfile = new GlideRecord('sn_hr_core_profile');
hrProfile.setWorkflow(false); //Avoid BS Rule before query which limits results for users
var profile = hrProfile.get(intuserid) ? hrProfile : null;

 

Example B : When you want to query a record in a script include which is in a different scope than the object , you need to have an additional script include.

 Example: script include below Global scope performing a query on HR Scope using the function getHrProfile

//get HR Profile by User_ID (sys_id) from a Script Include in a Global scope
var coreHRScript = new sn_hr_core.scriptsIncludeHrCore();
var grHrProfile = coreHRScript.getHrProfile(User_ID);

gs.info("HR Profile number: "+grHrProfile.getValue('number'));

Below an example script include in Human Resources: Core Scope having a function getHrProfile with a query with setworkflow(false) which avoids Before Business Rule queries.

var scriptsIncludeHrCore = Class.create();
scriptsIncludeHrCore.prototype = {

initialize: function() {},

getHrProfile: function(userId){
	var grHrProfile = new GlideRecord('sn_hr_core_profile');
	grHrProfile.addQuery('user', userId);
	grHrProfile.setWorkflow(false);
	grHrProfile.query();
	if (grHrProfile.next()) {
		return grHrProfile;
	}else{
		return;
	}
},

 

Please mark helpfull or answered when it does 🙂

 

regards, Peter