This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Passing a ID from a Form to a Method

didonato - Thursday, November 3, 2016 3:50 PM:

I'm trying to use a server side method that executes within a workflow. The method works fine if I hard-code the ID number EX - hd.setID("7811030AE0A747C7A7C1934A8C97532E")). How do I get the ID of the ITEM that is used in a form to pass to the method.


FORM is called: Min_Fielded_PR that comes from the ItemType called: Min_Fielded_PR
WORKFLOW is called: WF99
METHOD within the Workflow is called: MM99


// Method - MM99//
Innovator inn=this.getInnovator();
Item hd= inn.newItem("Min_Fielded_PR","get");
hd.setID(this.getID());
hd.setAttribute("select","item_number,description,resolution");
hd=hd.apply();
return this;



Yoann Maingon - Thursday, November 3, 2016 4:57 PM:

Hi Dominic, 

Here is a community method to retrieve the controlled item when a method is triggered from a workflow event:

gist.github.com/.../817184c84b7dec9e0dd3105c9d456632

call it from your method :

Item ControlledItem = this.apply("GetControlledItem");

PS: if you owe Eli a drink, remember that you owe me a cheese steak ! 



didonato - Friday, November 4, 2016 12:40 PM:

Sorry Yoann, but I need baby steps to do this. -

So I created a new Method called " GetControlledItem" and pasted everthing from the site you gave me.

I modifed my Method to this:

 

Innovator inn=this.getInnovator()

Item hd= inn.newItem("Min_Fielded_PR","get");

Item ControlledItem = this.apply("GetControlledItem");
hd.setID(ControlledItem);
hd.setAttribute("select","item_number,description,resolution");
hd=hd.apply();
return this;

 

I get error "CS1002, ; expected"

I guess I'm not calling the "GetControlledItem" Method correctly within my Method.

By the way, I think I owe you more than one cheesesteak!!

 



Yoann Maingon - Sunday, November 6, 2016 2:41 PM:

my first answer is that you are missing a ;

at the end of this line : Innovator inn=this.getInnovator()

try again then.




Yoann Maingon - Sunday, November 6, 2016 2:42 PM:

then in setID() you don't want to pass the item but just the Item ID

so it would be something like hd.setID(ControlledItem.getID());



didonato - Monday, November 7, 2016 6:33 PM:

THANK YOU Yoann,

That worked great. The last part to this method is retrieving the related Contact. I'm having trouble geting the ID for it. I think the problem is on the line that I underlined. What are you thoughts? It this incorrect?

Innovator inn=this.getInnovator();
Item hd= inn.newItem("Min_Fielded_PR","get");
Item hdRelatedContact = inn.newItem("Min_Fielded_PR_Contacts","get");
Item hdContact = inn.newItem("Min_Contact","get");

Item ControlledItem = this.apply("GetControlledItem");
hd.setID(ControlledItem.getID());

hd.setAttribute("select","item_number,description,problem_resolution");
hd.addRelationship(hdRelatedContact);
hdRelatedContact.setRelatedItem(hdContact);
hd=hd.apply();

hdRelatedContact = hd.getRelationships("Min_Fielded_PR_Contacts");

Item toUser= inn.newItem("Min_Contact","get");
toUser.setAttribute("select","email_primary");
toUser.setID(hdRelContact.getID());
toUser=toUser.apply();



Yoann Maingon - Monday, November 7, 2016 6:39 PM:

not sure as It's actually 1:00 am but try 

toUser.setID(hdRelContact.getProperty("related_id")) 

?



didonato - Thursday, November 10, 2016 1:13 PM:

I tried fixing this for hours and can't get this to work, any suggestions? I keep
getting "Not a single item" error

I tried the following and others without luck:
toUser.setID(hdRelContact.getID());
toUser.setID(hdRelContact.getProperty("related_id"));

*************************************

Innovator inn=this.getInnovator();
Item hd= inn.newItem("MIN_Fielded_PR","get");
Item hdRelatedContact = inn.newItem("MIN_Fielded_PR_Contacts","get");
Item hdContact = inn.newItem("MIN_Contact","get");
Item ControlledItem = this.apply("GetControlledItem");

hd.setID(ControlledItem.getID());
hd.setAttribute("select","item_number,description,problem_resolution");
hd.addRelationship(hdRelatedContact);
hdRelatedContact.setRelatedItem(hdContact);
hd=hd.apply();
hdRelatedContact = hd.getRelationships("MIN_Fielded_PR_Contacts");

Item toUser= inn.newItem("MIN_Contact","get");
toUser.setAttribute("select","email_primary");
toUser.setID(hdRelContact.getID());
toUser=toUser.apply();