Forum Discussion

conner_davis's avatar
conner_davis
Ideator I
2 years ago
Solved

Updating an Existing Property on Workflow vote

Hello,

After a user votes on a workflow, I want to update an existing property (_conversation_history). The code below is what I am using.

It appears that the code is generating the correct string in the variable (newconvo)), but it is not updating the property on the item?

Innovator inn = this.getInnovator();
Item controlledItem = this.apply("GetControlledItem");
if (controlledItem.isError()) {
return inn.newError("smc_TechInquiry_Notifications: Retrive Workflow: Unexpected error: " + controlledItem.getErrorString());
}
// get the message from requestor and reply to requestor

string messagefrom = controlledItem.getProperty("_message_from_requestor", "");
string replyTo = controlledItem.getProperty("_reply_to_requestor", "");
string history = controlledItem.getProperty("_conversation_history","");

string newconvo = history + " " + messagefrom + " " + replyTo;

string message = controlledItem.getPropertyCondition("_conversation_history");
this.setProperty("_conversation_history",newconvo);

return this;

Thank you for your help!

  • I don´t see any "apply" in your code. You set the Property, but only to the temporary context. You don´t seem to use edit/apply to actually save your new value. 

    And I see a second problem. As far as I understand you want to update your history value:

    You use this line to get the value:

    string history = controlledItem.getProperty("_conversation_history","");

    But that line to update the value:

    this.setProperty("_conversation_history",newconvo);

    In your context "this" represents the "Activity" item while controlledItem represent your change process. 
    I am not sure if controlledItem.setProperty in combination with edit/apply would work, cause the controlled item is something generated by the helper function. But you can give it a try. 

    If it doesn´t work, get the id of the controlledItem and do a direct edit of the Change process.

3 Replies

  • I don´t see any "apply" in your code. You set the Property, but only to the temporary context. You don´t seem to use edit/apply to actually save your new value. 

    And I see a second problem. As far as I understand you want to update your history value:

    You use this line to get the value:

    string history = controlledItem.getProperty("_conversation_history","");

    But that line to update the value:

    this.setProperty("_conversation_history",newconvo);

    In your context "this" represents the "Activity" item while controlledItem represent your change process. 
    I am not sure if controlledItem.setProperty in combination with edit/apply would work, cause the controlled item is something generated by the helper function. But you can give it a try. 

    If it doesn´t work, get the id of the controlledItem and do a direct edit of the Change process.

    • conner_davis's avatar
      conner_davis
      Ideator I

      Thank you very much! Below is the code that ended up working.

      Innovator inn = this.getInnovator();
      Item controlledItem = this.apply("GetControlledItem");
      if (controlledItem.isError()) {
      return inn.newError("smc_TechInquiry_Notifications: Retrive Workflow: Unexpected error: " + controlledItem.getErrorString());
      }
      // get the message from requestor and reply to requestor

      string messagefrom = controlledItem.getProperty("_message_from_requestor", "");
      string replyTo = controlledItem.getProperty("_reply_to_requestor", "");
      string history = controlledItem.getProperty("_conversation_history","");

      string newconvo = history + " " + messagefrom + " " + replyTo;

      string idofitem = controlledItem.getID();
      Item item2 = inn.getItemById("smc_TechInquiry",idofitem);
      item2.setProperty("_conversation_history",newconvo);
      item2.setProperty("_reply_to_requestor","");
      item2.setProperty("_message_from_requestor","");

      item2.setAction("edit");
      item2.apply();

      return this;

  • Using setProperty on an item does not inherently apply that change to the database. In this case, you are hoping to update the controlledItem, so you could update that item for an edit, then set the property, and apply.

    [embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:30cc4c6f-e88e-49d5-9de6-ff344e5e6dd0:type=csharp&text=controlledItem.setAction%28%22edit%22%29%3B%0AcontrolledItem.setProperty%28%22_conversation_history%22%2Cnewconvo%29%3B%0AcontrolledItem.apply%28%29%3B%0A]