Skip to main content
1-Visitor
May 28, 2015
Solved

Created user picker using datautility throws error on callback function.

  • May 28, 2015
  • 1 reply
  • 4329 views

Created a userpicker in a custom datautility and regiseterd it on a string attribute. Picker renders correctly in UI. On selecting user clicking finish windchill throws error for custom callback function saying that we cannot set value for null. Also mc.getRawValue() always returns null in the below code.

//Get datavalue method of datautilty

     public Object getDataValue(String component_id, Object object, ModelContext mc) throws WTException {

    buildUserPickerConfig(component_id, mc);

             Object localObject = null;

             System.out.println(mc.getRawValue());

             if (mc.getRawValue() != null)

             {

               localObject = mc.getRawValue();

               defaultProps.put(PickerRenderConfigs.DEFAULT_HIDDEN_VALUE, localObject.toString());

             } else

             {

               localObject = "";

             }

           PickerInputComponent pic = new PickerInputComponent("UserPicker",localObject.toString(), defaultProps);

     

           pic.setColumnName(component_id);    

           return pic;

        }

//Callback JS

function userPickerCallback(objects, pickerID)

{

var updateHiddenField =  document.getElementById(pickerID);

alert(updateHiddenField);

var myJSONObjects = objects.pickedObject;

for(var i=0; i< myJSONObjects.length;i++) {

var oid = myJSONObjects[i].oid;

alert(oid);

// Here “fullName” is the displayAttribute requested

updateHiddenField.value=oid;

}

}

Error Screenshot.

Screen Shot 05-28-15 at 11.09 AM.JPG

Best answer by psampath
public void buildUserPickerConfig(final String component_id,
final ModelContext mc) throws WTException {
// HashMap<String, Object> defaultProps = new HashMap<String, Object>();
defaultProps.put("pickerId", "userPluralID");
defaultProps.put("objectType", "wt.org.WTUser");
mc.getDescriptor().setProperties(defaultProps);
}

This solved it. I was adding callback in the config. I removed it and it worked. The default callback function works I guess.

1 reply

16-Pearl
June 1, 2015

Praveen,

Are you specifying any pickerCallback in the dataUtility? Also set the values for PickerRenderConfigs.PICKER_ATTRIBUTES with the required attributes that you want to show in the user interface and the value that needs to be persisted in database.

Regards,

Bhushan

psampath1-VisitorAuthorAnswer
1-Visitor
June 2, 2015
public void buildUserPickerConfig(final String component_id,
final ModelContext mc) throws WTException {
// HashMap<String, Object> defaultProps = new HashMap<String, Object>();
defaultProps.put("pickerId", "userPluralID");
defaultProps.put("objectType", "wt.org.WTUser");
mc.getDescriptor().setProperties(defaultProps);
}

This solved it. I was adding callback in the config. I removed it and it worked. The default callback function works I guess.

16-Pearl
June 2, 2015

Yes, OOTB callback function is provided, you can write your own if you need a different display or internal value.

Can you mark this thread as answered with your solution so that it helps others in future.