Integrations and APIs for Service

Get Involved. Join the Conversation.

Topic

    Dietrik
    Soap api: Adding product to answerAnswered
    Topic posted August 3, 2010 by Dietrik Black Diamond: 60,000+ Points, last edited February 20, 2012 by Dietrik Blue Ribbon: 750+ Points 
    2620 Views, 17 Comments
    Title:
    Soap api: Adding product to answer
    Content:

    Hi,

    I'm trying to add a product to an answer being created through the soap api using c#.

    The answer is being created without errors but the product is not linked to the answer.

    How should I add products when creating answers ?

    Here's the code i've used:

    Code Snippet:

    Best Comment

    Chris Omland

    Hi DS, looks like you discovered a product defect. I have entered an incident with our engineering team to get this addressed. In the meantime if you need to set the product you can get it done by Nil'ing or modifying CommonAttachments, CommonComments or OriginalReferenceNumber.

    For example in my code I did:            newAnswer.OriginalReferenceNumber = "000000-000000"; and this then caused the Product to be set correctly.

    -Chris

    Comment

    • Chris Omland

      Hi DS, looks like you discovered a product defect. I have entered an incident with our engineering team to get this addressed. In the meantime if you need to set the product you can get it done by Nil'ing or modifying CommonAttachments, CommonComments or OriginalReferenceNumber.

      For example in my code I did:            newAnswer.OriginalReferenceNumber = "000000-000000"; and this then caused the Product to be set correctly.

      -Chris

    • Dietrik

      Thanks Chris, seems to work for categories as well. Do I get beer for every bug I find ?

    • Chris Omland

      Thanks for the heads up on categories. No comment on the beer :)

    • Steve D.

      How timely. Today I tried to associate a Product with an Answer and it failed. Then I found this posting (thank you both). Previously I opened an Incident (100618-000167) titled: StaffGroup is null when AssignedTo is set using WebServices. I can't help but wonder if the two problems are related (i.e. bug in shared base code). Note: Setting Access Level seems to fail as well.

      Chris, in your response you stated:"In the meantime if you need to set the product you can get it done by Nil'ing or modifying CommonAttachments, CommonComments or OriginalReferenceNumber.  For example in my code I did:            newAnswer.OriginalReferenceNumber = "000000-000000"; and this then caused the Product to be set correctly."

      Could you please provide a bit more detail on "Nil'ing" or using newAnswer.OriginalReference?

      In my test code I am attempting to update an existing Answer as follows:
      
              //Create an Answer object
      Answer answer = new Answer();
      ID ansID = new ID();
      ansID.setId(100);
      answer.setID(ansID);

      //Set some properties on the Answer that should be updated.
      NamedIDHierarchyList nihlProduct = new NamedIDHierarchyList();
      NamedIDHierarchy nihProd = new NamedIDHierarchy();
      ID dryLabID = new ID();
      dryLabID.setId(10);
      nihProd.setID(dryLabID);
      nihlProduct.addNamedIDHierarchyList(nihProd);
      answer.setProducts(nihlProduct);

      // Set AccessLevel Status Public
      NamedID swtNamedID = new NamedID();
      ID swtId = new ID();
      swtId.setId(4);
      swtNamedID.setID(swtId);
      StatusWithType swt = new StatusWithType();
      swt.setStatus(swtNamedID);
      answer.setStatusWithType(swt);

      There are no Incidents associated to the products so it seems the relationship between Answer and Product would have to be through the MetaAnswer entity.

      How would I set the Product and AccessLevel properties for an Answer by "Nil'ing" or modifying OriginalReferenceNumber?
    • Chris Omland

      Just set the original reference number to '000000-000000' and that should set the product/category. If the original refno is important to you, you might need to save it off and then update it after setting it to '000000-000000'. Let me check on the StaffGroup and AccessLevel.

      Thanks.

    • Steve D.

      Thanks for the response Chris but still no SOAP :-}

              //Create and set the Id property
      ID ansID = new ID();
      ansID.setId(100);
      answer.setID(ansID);
      answer.setOriginalReferenceNumber("000000-000000");

      //Set some properties on the Answer that should be updated.
      NamedIDHierarchyList nihlProduct = new NamedIDHierarchyList();
      NamedIDHierarchy nihProd = new NamedIDHierarchy();
      ID dryLabID = new ID();
      dryLabID.setId(10);
      nihProd.setID(dryLabID);
      nihlProduct.addNamedIDHierarchyList(nihProd);
      answer.setProducts(nihlProduct);

      The Audit Log for the Answer shows my update but there are no Products listed for the Answer.

      Any other suggestions?
    • Chris Omland

      Hmmm, well one difference is I use the setNamedIDHierarchList method and not the add. So my code looks like this:

      NamedIDHierarchy prodNameId = new NamedIDHierarchy();
      ID prodID = new ID();
      prodID.setId(20);
      prodNameId.setID(prodID);
      NamedIDHierarchy[] namedIdHierarchyArray = new NamedIDHierarchy[] { prodNameId };
      NamedIDHierarchyList namedIdHierarchyList = new NamedIDHierarchyList();
      namedIdHierarchyList.setNamedIDHierarchyList(namedIdHierarchyArray);
      newAnswer.setOriginalReferenceNumber("000000-000000");

      Can you try that approach?

    • Steve D.

      That did it!

      Two things I noticed:

      1 - You created a NamedIDHierarchy array and made the ID an element in the array, then added the array to the List. Whereas I simply added the ID directly to the List.

              NamedIDHierarchy prodNameId = new NamedIDHierarchy();
              ID prodID = new ID();
              prodID.setId(10);
              prodNameId.setID(prodID);
              NamedIDHierarchy[] namedIdHierarchyArray = new NamedIDHierarchy[] { prodNameId };
              NamedIDHierarchyList namedIdHierarchyList = new NamedIDHierarchyList();
              namedIdHierarchyList.setNamedIDHierarchyList(namedIdHierarchyArray);
              answer.setOriginalReferenceNumber("000000-000000");
              answer.setProducts(namedIdHierarchyList);

      2 - I added the last line of code answer.setProducts(namedIdHierarchyList); to add the list to the Answer.

      Thank you so much for your help. I'll buy you a drink when I see you next week in Bozeman.

    • Chris Omland

      Glad it worked! See you next week.

    • Dietrik

      I haven't seen anything strange with setting accesslevels or assignedto.

    • Chris Omland

      I'm still looking into AssignedTo and access levels. I was able to get AssignedTo to work fine yesterday but I need to read the incident in detail to understand what was reported.

    • Steve D.

      Chris,

      You may want to examine the AnswerCreate.java code attached to the Incident.

      It may be that the code I used for my tests is incorrect:

                  // Set AccessLevel Status Public
      NamedID swtNamedID = new NamedID();
      ID swtId = new ID();
      swtId.setId(4);
      swtNamedID.setID(swtId);
      StatusWithType swt = new StatusWithType();
      swt.setStatus(swtNamedID);

      newAnswer.setStatusWithType(swt);
                  // Account ID=14 - Steve Deal
      NamedID acctNamedID = new NamedID();
      ID acctId = new ID();
      acctId.setId(14);
      acctNamedID.setID(acctId);
      // GroupAccount=52 - Project Team
      NamedID grpNamedID = new NamedID();
      ID grpId = new ID();
      grpId.setId(52);
      grpNamedID.setID(grpId);
      GroupAccount groupAccount = new GroupAccount();
      groupAccount.setAccount(grpNamedID);

      newAnswer.setAssignedTo(groupAccount);

      I would greatly appreciate your review of my test code. Does this look correct to you?


    • Ricardo Sousa

      I don't know if is related with the same bug but I'm not able to set the AccessLevels using the SOAP API

      C# code:

      Answer answer = new Answer();
      answer.OriginalReferenceNumber = "000000-000000";

      answer.Question = "Test Question";
      answer.Solution = "Test Solution";

      answer.Summary = "Test Summary";

      answer.Language = new NamedID();
      answer.Language.ID = new ID();
      answer.Language.ID.idSpecified = true;
      answer.Language.ID.id = 1;

      NamedIDDelta accessLevel = new NamedIDDelta();
      accessLevel.ID = new ID();
      accessLevel.ID.idSpecified = true;
      accessLevel.ID.id = 4;

      NamedIDDelta[] accessLevels = { accessLevel};
      answer.AccessLevels = accessLevels;

      answer.AnswerType = new NamedID();
      answer.AnswerType.Name = "HTML";

      answer.AssignedTo = new GroupAccount();
      answer.AssignedTo.Account = new NamedID();
      answer.AssignedTo.Account.Name = answerAssignedAccount;

      answer.AssignedTo.StaffGroup = new NamedID();
      answer.AssignedTo.StaffGroup.Name = answerAssignedGroup;

      answer.StatusWithType = new StatusWithType();

      answer.StatusWithType.Status = new NamedID();
      answer.StatusWithType.Status.Name = answerStatus;

      CreateProcessingOptions createProcessingOptions = new CreateProcessingOptions();
      createProcessingOptions.SuppressExternalEvents = false;
      createProcessingOptions.SuppressRules = false;

      ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
      clientInfoHeader.AppID = ".NET Getting Started";

      RNObject[] createObjects = new RNObject[] { answer };

      RNObject[] createResults = _service.Create(clientInfoHeader, createObjects, createProcessingOptions);



      You were able to do that?

      Best regards,
      Ricardo

    • Dave Arnold

      I'm have the same issue as Ricardo.  Here is the soap body I'm attempting to use, the answer is created but the Access Level is not getting set.  No error is generating. 

      Using version May 2011

      <soapenv:Body>
              <ns7:Create xmlns:ns7="urn:messages.ws.rightnow.com/v1">
                   <ns7:RNObjects xmlns:ns4="urn:objects.ws.rightnow.com/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns4:Answer">
      <ns4:AccessLevels>
      <NamedIDDeltaList xmlns="urn:base.ws.rightnow.com/v1">
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="4" />
      </NamedIDDeltaList>
      </ns4:AccessLevels>
      <ns4:AnswerType>
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="1" />
      </ns4:AnswerType>
      <ns4:Categories>
      <NamedIDHierarchyList xmlns="urn:base.ws.rightnow.com/v1">
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="5" />
      </NamedIDHierarchyList>
      </ns4:Categories>
      <ns4:Language>
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="1" />
      </ns4:Language>
      <ns4:Question>Question Text</ns4:Question>
      <ns4:Solution><![CDATA[Solution Text]]></ns4:Solution>
      <ns4:StatusWithType>
      <ns4:Status>
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="4" />
      </ns4:Status>
      </ns4:StatusWithType>
      <ns4:Summary>Summary Text</ns4:Summary>
                  </ns7:RNObjects>
                  <ns7:ProcessingOptions>
                      <ns7:SuppressExternalEvents>false</ns7:SuppressExternalEvents>
                      <ns7:SuppressRules>false</ns7:SuppressRules>
                  </ns7:ProcessingOptions>
              </ns7:Update>
          </soapenv:Body>
       
      Can anyone provide a working soap example that creates an answer and sets the accesslevel?

       

    • Dave Arnold

      I figured it out.  Just need to specify the action on NamedIDDeltaList.

       

       

      <soapenv:Body>
              <ns7:Create xmlns:ns7="urn:messages.ws.rightnow.com/v1">
                   <ns7:RNObjects xmlns:ns4="urn:objects.ws.rightnow.com/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns4:Answer">
      <ns4:AccessLevels>
      <NamedIDDeltaList xmlns="urn:base.ws.rightnow.com/v1" action="add">
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="4" />
      </NamedIDDeltaList>
      </ns4:AccessLevels>
      <ns4:AnswerType>
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="1" />
      </ns4:AnswerType>
      <ns4:Categories>
      <NamedIDHierarchyList xmlns="urn:base.ws.rightnow.com/v1">
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="5" />
      </NamedIDHierarchyList>
      </ns4:Categories>
      <ns4:Language>
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="1" />
      </ns4:Language>
      <ns4:Question>Question Text</ns4:Question>
      <ns4:Solution><![CDATA[Solution Text]]></ns4:Solution>
      <ns4:StatusWithType>
      <ns4:Status>
      <ID xmlns="urn:base.ws.rightnow.com/v1" id="4" />
      </ns4:Status>
      </ns4:StatusWithType>
      <ns4:Summary>Summary Text</ns4:Summary>
                  </ns7:RNObjects>
                  <ns7:ProcessingOptions>
                      <ns7:SuppressExternalEvents>false</ns7:SuppressExternalEvents>
                      <ns7:SuppressRules>false</ns7:SuppressRules>
                  </ns7:ProcessingOptions>
              </ns7:Update>
          </soapenv:Body>