Null value is getting displayed in reference field

suuriya
Tera Contributor

HI Community,

 

I have a requirement; task needs to be assigned to requested for's hub.

Requester's hub assignment group can be found in the field called Hub on the Location form of the location the requester is assigned to. For example, if the requester's location (mentioned in the Location field of their user profile) is OH-Ohio-Work then the hub assignment group for this location mentioned in the Hub field of this location screen will be the one the above-mentioned task will be sent to.

 

For that i have created a catalog task and in advanced condition written this script

var names = current.variables.common_vars_requested_for;
var loc = names.location;
var hubs = loc.u_hub;
gs.addInfoMessage(hubs);
task.assignment_group = hubs.getDisplayValue();
Task is generated with an empty assignment group...it seems null value is getting displayed, but it is not completely empty...so to check added the info message there it is showing the correct name but in task assignment group it is showing null value 
Please let me know how we can fix this
suuriya_0-1715087672760.png

 

 

Thanks in Advance!

1 ACCEPTED SOLUTION

Oh well if its a group, you need to change cmn_location to sys_user_group

View solution in original post

13 REPLIES 13

suuriya
Tera Contributor

HI @Kieran Anson 

 

The hub field in location form is single line text field is something to do with that because of that is it causing issue 

suuriya_1-1715094641113.png

because in xml i can see empty display value and no sys id is present

Ah yes that would cause an issue as it's not a reference. You should perform a lookup to ensure the value is a valid location record

var hubName = hubs.getValue()
var locationGR = new GlideRecord('cmn_location');
locationGR.setLimit(1);
locationGR.addQuery('name' , hubName);
locationGR.query();
if(locationGR.next()){
	task.setValue('assignment_group' , locationGR.getUniqueValue());
}

HI @Kieran Anson 

 

I tried like this but no the task assignment group is empty like no value is there

var names = current.variables.common_vars_requested_for;
var loc = names.location;
var hubs = loc.u_hub;
gs.addInfoMessage(hubs);
var hubName = hubs.getValue();
gs.addInfoMessage(hubName);
var locationGR = new GlideRecord('cmn_location');
locationGR.setLimit(1);
locationGR.addQuery('name' , hubName);
locationGR.query();
if(locationGR.next()){
    task.setValue('assignment_group' , locationGR.getUniqueValue());
}

//task.setValue('assignment_group' , hubs.getDisplayValue());
 
can you please let me know what i did wrong here and the second info message itself didn't display only first annotation appeared

Are you sure the hubName being used is a valid location? If you search for it manually, can you find a location with that name?

Hi @Kieran Anson 

 

Actually the hub field (single line) in location form stores the data/value of group name and task needs to be assigned to that group and yes I checked in groups table the hubname value that group is present