The CreatorCon Call for Content is officially open! Get started here.

How Can I autopopulate 'Location' Reference field with same value as shown in Space Reference field

WazzaJC
Tera Expert

How Can I auto-populate 'Location' Reference field with same value as shown in Space Reference field

Hi Guys,

 

I have built a few Reference fields, Building (u_building), Floor (u_floor) and Space (u_space) field on my Incident Form (see screenshot attached). These are all Reference fields.

 

These are all driven/referenced directly from the Location (cmn_location) table.

 

I also have the standard 'Location' field, which also references the Location table.

 

How can I write either a script or business rule, so that when the Space (u_space) field gets populated with a location value, at the same time the Location (location) field will then also get updated with the same location value, that is referenced within the 'Space' (u_space) field ?

 

I assume this is either a Business Rule or perhaps onChange Client Script?

 

Please see my screenshot attached, showing the relevant fields.

 

I would appreciate any help/guidance with achieving this.

 

Many Thanks.

20 REPLIES 20

@WazzaJC  the parameter name in Script Include and Client Script needs to be the same but the name is free and has nothing to do with the field name: 

Client Script:   ga.addParam('sysparm_space', newValue); // 1. parameter name you need to use in the Script Include and 2. parameter is the new value in the u_space field.

Business Rule: 

var space = this.getParameter('sysparm_space');
 
This is how my Script Include looks like :
DanielBorkowi1_0-1686549508954.png

I don't have the Access Role check in because  I didn't activated the Privacy on Client Callable Script Includes on my PDI. It is described here: https://docs.servicenow.com/bundle/utah-platform-security/page/administer/security/reference/privacy....

You can select snc_internal so that all Internal User can use this logic or you select a role which is allowed to write Incident - check the ACL of Incident table, who is allowed to write on Incident table.

 

Btw. I adjusted the post with the script, because you wanted to have the Space in the original location field populated. Please mark the Post with the scripts as correct, if this answers your initial question.

 

Greets

Daniel

 

Hi Daniel - I just cannot get these scripts to work.

I am applying them exactly as you have them above, to my Client's Instance, in exactly this format and following your instructions and it just will not work but I cannot work out why.

I am so grateful that you tried to help me with this solution - I really wish I could get it to work for me but still no success.

If you do think of anything or anything above that may have not been covered, I'd really appreciate in case I have missed anything, but I understand if not possible because you are busy.

Many thanks once again Daniel.

Kind Regards, Warwick

Hi @WazzaJC, I only created the fields u_building, u_space, u_floor  as reference (Location) fields on Incident. Created the Script Include and Client Script in global Scope. An renamed the Location Type for Buildings. Then I created these Location with parent references as shown in the picture. I'll provide you my Update Set (this includes also the test data). Maybe some Screenshot of your configuration will help, maybe as private message.  

 

Thank You very much for this Daniel, much appreciated.

Ok sure - maybe I will need to reach out to you on Private Message, I will indeed do that when I get some time.

Quick question - when you say you need to 'Rename Location Type for Buildings'?

Maybe this is the step I still need to do on my Client's Instance, for your Scripts to work ?

I have not done any Location Type Renaming yet - what do I need to rename in Location Type.

At the moment there is standard Location Type in the Client's instance eg. Location Type = Building, Location Type = Floor, Location Type = Space for example.

Do I need to be changing these in anyway ?

Many thanks Daniel.

@WazzaJC Please check also the choice value of the type building in my PDI it was building/structure an this caused some issues in my solution, because I use the value as attribute in my result object and this special character "/" was disturbing.