Expand my Community achievements bar.

How come null can not be captured?

Avatar

Former Community Member
When the attribute (Dept) returned is null, I can not figure out how to check for the condition. If I don't append with blank, I will get an error. If I append blank, the result is "null".



function SetUserAttribute(sField, sAttribute)

{ var oParticipant = WorkItem.assignedTo;

if (oParticipant != null) {

var str = oParticipant.attributes.item(sAttribute);

if ((str != null) && (str != "null")) {

WorkItem.setFieldValue(sField,str+"");

}

}

}
1 Reply

Avatar

Former Community Member
Peter,



Since we are dealing with an Attribute object as our return value the conditional stmt to check for null should be against the property 'value'. As such...



void function SetUserAttribute(sField, sAttribute) {



var oParticipant = WorkItem.assignedTo;

if (oParticipant != null) {

var oAttrib = oParticipant.attributes.item(sAttribute);

if (oAttrib.value != null ) {

//WorkItem.setFieldValue(sField,str+"");

Agent.log(sField + " = " + oAttrib.value);

}

else

Agent.log(sField + " is EMPTY!");

}

}