Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Record Producer variable linked to reference field not taking a value

andysummers
Tera Expert

Hello,

I have just finished deploying a large update set from o_ur Test environment to Production and most of it has worked exactly as planned in production with the exception of 1 really irritating bug that I have found.

Test was cloned to Production before we went live with SN a few months ago and this deployment today pretty much brings them back to the same code base after we added a new custom app.

Production is running : glide-geneva-08-25-2015__patch6-hotfix2-05-18-2016

Test is running : glide-geneva-08-25-2015__patch6-hotfix2-05-18-2016

I have circa 25 record producers with their own tables, all extended from one parent table that extends Task. On the record producers, I have a variable set for common variables across all the Record Producers. In that called set, I have a variable called Opco which is the Company field on the Task table basically, a reference field to core_company.

In the variable set there are a number of Catalog Client Scripts to set some values on the new record producers, one being to go and grab the current user's Company and put it on the new record in the company field/variable. There is some logic around when this runs - if a user is an admin the field isn't set because they can raise tickets for all users in all companies. If the user is not an admin, the field is set with their own company and then made readonly so they can't change it on the record producer.

The Catalog Client Script makes an Ajax call to a function that checks if you're an admin or not, and if not it returns the sys_id of the user's company record.

The Client Catalog Script then runs this code to set the Company reference variable on the Record Producer:

find_real_file.png

find_real_file.png

In Firebug I see the Client Script message with a valid sys_id and the company variable contains the name of the user's Company - all works perfect in Test.

In Production however I see a totally weird behaviour. The first time the Record Producer loads for a new session, the company name is populated correctly , and the field is set to read only.

find_real_file.png

The next time I load the record producer or go to another one that shares the same variable set, the script runs, the console log in Firebug shows the sys_id of the company, and I can see that the field is no longer mandatory and it is read only, BUT the company name does not display and for some reason the field has collapsed to around 40% of the normal width. There's also no button to open the related record.

find_real_file.png

I have tried everything! I removed the Set Mandatory and Set Readonly commands in the Client Catalog Script, and reload the page to see a company name present. Then reload again and it's not there any more. The field remains visually correct however, it does not shrink. So it's the ReadOnly function that seems to cause the field to shrink for some reason. That's one half of the problem, the other is that the company doesn't display. It's erratic behaviour - make a change to the script and I get this again (the correct behaviour)

find_real_file.png

reload the page again and I get this :

find_real_file.png

This happens consistently in our Production environment only, in both Chrome and IE 11, and Chrome on Mac.

For now I have had to remove the script that sets the field to be mandatory and readonly but the business have a requirement to prevent users raising requests outside of their own company. I can't even get it to reliably populate the opco variable even with the readonly and mandatory code removed, most of the time the page loads and I just see :

find_real_file.png

Does anyone have ANY ideas what could be causing this or how to fix? I have been looking at it all day, and in Dev and Test where the code is identical to Production for the client scripts that are running here, it has always worked. The fact that every now and then I get a company name populated surely means it's not an ACL issue - but I have checked the Access for the users and can browse the core_company table and view the records there so I'm pretty sure it's not that.

It's just being WEIRD!

9 REPLIES 9

oharel
Kilo Sage

Do you see any errors in the browser's java console?


Do you have any DOM manipulation in the script, or maybe in another script, related to the page?


I had something similar with a client script that had wrong conditions set into it, which caused the page to go "crazy" for some users (but not all) and display strange behavior.


Perhaps you can throw up your client script and the script include you're calling as well.



//Göran


The Catalog Client Script looks like this :



function onLoad() {


  //Type appropriate comment here, and begin script below



  //GlideAjax Async query to Script Include FPSharedServiceFunctions.


  var ajax_groupMembership_query = new GlideAjax('FPSharedServiceFunctions');


  ajax_groupMembership_query.addParam('sysparm_name','OpcoGroupUserMembership');


  ajax_groupMembership_query.getXML(queryresult);



}




//Function Returned


function queryresult(response)


{


            var answer = response.responseXML.documentElement.getAttribute("answer");


            console.log("Client Script: answer = " + answer);


            //Check if an answer is returned.


            if(answer)


            {


                      var get_form_opco = g_form.getValue('company');


                      //If record is not submitted yet


                      if((answer != 'Group Membership True') && (get_form_opco == ''))


                      {


                                console.log("Client Script: setting company");


                                g_form.setValue('company', answer);


                                //g_form.setMandatory('company', false);


                                //g_form.setReadOnly('company', true);


                                }


                    }


        }




And the Script Include for FPSharedServiceFunctions is this :



var FPSharedServiceFunctions = Class.create();


FPSharedServiceFunctions.prototype = Object.extendsObject(AbstractAjaxProcessor, {



  OpcoGroupUserMembership: function()


  {


            try


            {


                      //Set Flag variable


                      var set_result = "Group Membership False";



                      //GR user groups to get the list of groups which start with name EMEA-RSS/EMEA-RCAP/EMEA-SSC.


                      var q_checkGroupMem = new GlideRecord('sys_user_group');


                      var q_AddOrCondition = q_checkGroupMem.addQuery('name', 'STARTSWITH', 'EMEA-RSS');


                      q_AddOrCondition.addOrCondition('name', 'STARTSWITH', 'EMEA-RCAP');


                      q_AddOrCondition.addOrCondition('name', 'STARTSWITH', 'EMEA-SSC');


                      q_checkGroupMem.query();


                      while(q_checkGroupMem.next())


                                {


                                //Check if the Logged in user is a member of any one of the returned groups.


                                if(gs.getUser().isMemberOf(q_checkGroupMem.name))


                                {


                                          set_result = "Group Membership True";


                                }


                                }



                      //If user is NOT a member of any group returned above then return its own company record sys.


                      if(set_result == 'Group Membership False')


                        {


                                var User_company_sys = gs.getUser().getCompanyID();


                                set_result = User_company_sys;


                      }


                      gs.info("Ricoh debugging Script include executed, final result : " + set_result);



                      return set_result;


  }


  catch (err)


  {


            gs.log("Error in executing function OpcoGroupUserMembership " + err,"+++ logging") ;


  }


  },



  type: 'FPSharedServiceFunctions'


});


The scripts seem OK to me (but maybe goranlundqvist can see more ).


So... do you have any errors in the java console when the page loads? Try in both cases - when it gets populated correctly and when it doesn't.