Hi guys
I want to get the User id of a referenced element which has been added as a model element
For example, I have a Task element which has a reference to a use-case element
Using the below code I can get the model element of the referenced element but when I try to get its view it returns a null value.
This code will not work and it causes a null pointer exception on the fourth line because the view object is null. I have used the getMasterView() method before and it worked fine but in this case and for a reference that has been added as a model element it not work and returns null.
Would you please help me find the user id of that use-case element?
Thanks in advance
We are not very certain about what you mean by task here. Do you mean BPMN task? And what sort of “reference” do you mean? Model element reference? Could you post some screenshots for referencing?
Hi @Jick and thanks for your reply
I tested your code for both references as model element and references as shape but userIdProp is null every time.
I tested that using this code :
IModelElement modelElement; // assume i have access to model element of the task
IBPTask task = (IBPTask) modelElement;
for(IReference reference : task.toReferenceArray()) {
if(reference.getUrlAsModel() != null || reference.getUrlAsShape() != null ) {
IModelProperty userIdProp = reference.getModelPropertyByName(IUseCase.PROP_USER_ID);
if (userIdProp != null) {
return userIdProp.getValueAsString();
} else {
return null;
}
}
}