I wanna call script include value and set in business rule of custom field value

Anish9515
Tera Contributor

scriptincludefunction: function(current) {

var groupId = gs.getProperty("group_user");
        var test = new GlideRecord("sys_user_grmember");
        test.addEncodedQuery("group=" + groupId);
        test.query();
 
        while (test.next()) {
            if (field1.indexOf(test.user.toString()) == -1 && field2.user.toString().indexOf(requester) == -1) {
                if (checking) {
                    checking += ',' + test.user.toString();
                } else {
                    checking = test.user.toString();
                }
            }
I wanna  checking value to set on the business rule field that is list 
In Business rule syntax:-
var x = new scriptincludename();
u_field_name = x.scriptincludefunction(current.checking);
 
In script include checking values should be set u_field_name 
Please help me to how to write syntax on BR to get value from script include

@Ankur Bawiskar 

3 REPLIES 3

Najmuddin Mohd
Mega Sage

Hi @Anish9515 ,

You need to add a return statement.

scriptincludefunction: function(current) {

var groupId = gs.getProperty("group_user");
        var test = new GlideRecord("sys_user_grmember");
        test.addEncodedQuery("group=" + groupId);
        test.query();
 
        while (test.next()) {
            if (field1.indexOf(test.user.toString()) == -1 && field2.user.toString().indexOf(requester) == -1) {
                if (checking) {
                    checking += ',' + test.user.toString();
                } else {
                    checking = test.user.toString();
                  }
              }
         }

       return checking;

}


And write the business rule, with conditions Before Insert/Update.

u_field_name = new scriptincludename().scriptIncludefunction();

If the above information helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

 

@Najmuddin Mohd 
Using logs I have noticed , checking has sysid's , How to return those sysyid in script include
My custom field type is "LIST" , How to set those sysid
your syntax is working but how to set those sysid

Tai Vu
Kilo Patron
Kilo Patron

Hi @Anish9515 

It looks like there might be a few points of confusion in your script. Here are some areas to review:

  1. The parameter current is defined but never used in the function.
  2. Variables field1 and field2 are called, but it’s unclear where they’re defined.
  3. The requester variable also appears to be missing a definition.
  4. There's no checking variable defined before it's used

Could you provide more details on what you’re aiming to accomplish with this code? It’ll help us offer more precise guidance.

 

Cheers,

Tai Vu