web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Request xml : System.ArgumentException : Requiered field "Target" is missing

(0) ShareShare
ReportReport
Posted on by 15

Hello!

I'm trying to trigger an action using xml called after a click on a button and I can't get rid of this error : System.ArgumentException : Requiered field "Target" is missing.

I really don't know what's happening.

Any ideas?

Thanks.


Here is my code :

       var requestName = "bdf_AppelPluginDevis";
        var requestXML = ""
        requestXML += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";
        requestXML += "<s:Body>";
        requestXML += "<Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i= \"www.w3.org/.../XMLSchema-instance\">";
        requestXML += "<request  xmlns:a=\"schemas.microsoft.com/.../Contracts\">";


        requestXML += "<b:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">";
        requestXML += "<a:KeyValuePairOfStringanyType>";
        requestXML += "<b:key>Target</b:key>";
        requestXML += "<b:value i:type=\"a:EntityReference\">";
        requestXML += "<a:id>" + Xrm.Page.data.entity.getId() + "</a:id>";
        requestXML += "<a:LogicalName>" + Xrm.Page.data.entity.getEntityName() + "</a:LogicalName>";
        requestXML += "<a:name i:nil=\"true\">";
        requestXML += "</a:name></b:value>";
        requestXML += "</a:KeyValuePairOfStringanyType>";
        requestXML += "</a:Parameters>";

        requestXML += "<a:RequestId i:nil=\"true\"></a:RequestId>";
        requestXML += "<a:RequestName>" + requestName + "</a:RequestName>";
        requestXML += "</request>";
        requestXML += "</Execute>";
        requestXML += "</s:Body>";
        requestXML += "</s:Envelope>";

        var req = new XMLHttpRequest();
        req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", false)
        req.setRequestHeader("Accept", "application/xml, text/xml, */*");
        req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        req.setRequestHeader("Content-Length", requestXML.length);
        req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
        req.send(requestXML);

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    SrinivasCh Profile Picture
    572 on at
    RE: Request xml : System.ArgumentException : Requiered field "Target" is missing

    Hi Olivier33,

    May you check whether you are receiving  correct value for Xrm.Page.data.entity.getId() which is sent as target?

    i suggest to do a check on that value and it's type.

    Also, i see you are missing one more line

    <request i:type=\"a:\RequestType(AssignRequest etcc..)"");

    Hope this helps!!

    Mark this questions as answered, if you find answer for your question :)

  • Olivier33 Profile Picture
    15 on at
    RE: Request xml : System.ArgumentException : Requiered field "Target" is missing

    Thanks for your help.

    I added i:type=\"a:RetrieveRequest\" to my request.

    Xrm.Page.data.entity.getId() seems to return the correct value : {XXX-XXX-XX...}.

    I tried to write a wrong id and it shows me the same error.

    So i tried to write the good id in lower case, upper case and without "{" and "}" but nothing changes.

    FI i try to trigger an empty action on an active quote (read only form) to trigger a plugin.

  • Suggested answer
    MehrCrm Profile Picture
    290 on at
    RE: Request xml : System.ArgumentException : Requiered field "Target" is missing

    You have a mismatch tag in you XML:

    requestXML += "<b:Parameters xmlns:c=\"schemas.datacontract.org/.../System.Collections.Generic\">";

    ....

    requestXML += "</a:Parameters>";

    Change <b: to <a: and try again.

  • Olivier33 Profile Picture
    15 on at
    RE: Request xml : System.ArgumentException : Requiered field "Target" is missing

    Hi! Thanks for helping.

    I still get the error. Here is my code :      

    var requestXML = ""

           requestXML += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";

           requestXML += "<s:Body>";

           requestXML += "<Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i= \"www.w3.org/.../XMLSchema-instance\">";

           requestXML += "<request i:type=\"a:RetrieveRequest\" xmlns:a=\"schemas.microsoft.com/.../Contracts\">";

           requestXML += " <a:Parameters  xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\">";

           requestXML += " <a:KeyValuePairOfStringanyType>";

           requestXML += " <b:key>Target</b:key>";

           requestXML += " <b:value i:type=\"a:EntityReference\">";

           requestXML += " <a:id>" + Xrm.Page.data.entity.getId() + "</a:id>";

           requestXML += " <a:LogicalName>" + Xrm.Page.data.entity.getEntityName() + "</a:LogicalName>";

           requestXML += " <a:name i:nil=\"true\">";

           requestXML += " </a:name></b:value>";

           requestXML += " </a:KeyValuePairOfStringanyType>";

           requestXML += " </a:Parameters >";

  • MehrCrm Profile Picture
    290 on at
    RE: Request xml : System.ArgumentException : Requiered field "Target" is missing

    You don't need to add i:type=\"a:RetrieveRequest\" part to request. Please find below a function that I have used to call actions in the past.

    function ActionCall(ActionName, Guid, EntityLogicalName) {

       var requestXML = ""

       requestXML += "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";

       requestXML += "  <s:Body>";

       requestXML += "    <Execute xmlns=\"schemas.microsoft.com/.../Services\" xmlns:i=\"www.w3.org/.../XMLSchema-instance\">";

       requestXML += "      <request xmlns:a=\"schemas.microsoft.com/.../Contracts\">";

       requestXML += "        <a:Parameters xmlns:b=\"schemas.datacontract.org/.../System.Collections.Generic\">";

       requestXML += "          <a:KeyValuePairOfstringanyType>";

       requestXML += "            <b:key>Target</b:key>";

       requestXML += "            <b:value i:type=\"a:EntityReference\">";

       requestXML += "              <a:Id>" + Guid + "</a:Id>";

       requestXML += "              <a:LogicalName>" + EntityLogicalName + "</a:LogicalName>";

       requestXML += "              <a:Name i:nil=\"true\" />";

       requestXML += "            </b:value>";

       requestXML += "          </a:KeyValuePairOfstringanyType>";

       requestXML += "        </a:Parameters>";

       requestXML += "        <a:RequestId i:nil=\"true\" />";

       requestXML += "        <a:RequestName>" + ActionName + "</a:RequestName>";

       requestXML += "      </request>";

       requestXML += "    </Execute>";

       requestXML += "  </s:Body>";

       requestXML += "</s:Envelope>";

    // Using Jquery. Asynch

       $.ajax(

       {

           type: "POST",

           contentType: "text/xml;charset=utf-8",

           datatype: "xml",

           url: Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web",

           data: requestXML,

           beforeSend: function (XMLHttpRequest) {

               XMLHttpRequest.setRequestHeader("Accept", "application/xml, text/xml, */*");

               XMLHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute&quot;);

    XMLHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

    XMLHttpRequest.setRequestHeader("Content-Length", requestXML.length);

           },

           success: function (data, textStatus, XmlHttpRequest) {

               console.log("Action call completed. ....");

           },

           error: function (XMLHttpRequest, textStatus, errorThrown) {

               console.log("Unable to call action....");

           }

       });

    // or use XMLHttpRequest directly.

    /*

           var req = new XMLHttpRequest();

           req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", false)

           req.setRequestHeader("Accept", "application/xml, text/xml, */*");

           req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");

           req.setRequestHeader("Content-Length", requestXML.length);

           req.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");

           req.send(requestXML);

    */

    }

    And to call the above function:

    ActionCall("bdf_AppelPluginDevis", Xrm.Page.data.entity.getId(), Xrm.Page.data.entity.getEntityName());

  • Suggested answer
    SrinivasCh Profile Picture
    572 on at
    RE: Request xml : System.ArgumentException : Requiered field "Target" is missing

    Hope you have resolved issue..

    If not, I am providing one more example.

    let us say i want to create a contact with name as "Test2"

         Entity entContact = new Entity("contact");

            entContact.Attributes["firstname"] = "Test2";

            slos.Create(entContact);

    HTTP REQUEST

    --------------------------------------------------

    POST thinkcrm1.api.crm8.dynamics.com/.../web

    Content-Type: text/xml; charset=utf-8

    SOAPAction: schemas.microsoft.com/.../Create

    <s:Envelope xmlns:s="schemas.xmlsoap.org/.../&quot;>

     <s:Body>

       <Create xmlns="schemas.microsoft.com/.../Services&quot; xmlns:i="www.w3.org/.../XMLSchema-instance&quot;>

         <entity xmlns:a="schemas.microsoft.com/.../Contracts&quot;>

           <a:Attributes xmlns:b="schemas.datacontract.org/.../System.Collections.Generic&quot;>

             <a:KeyValuePairOfstringanyType>

               <b:key>firstname</b:key>

               <b:value i:type="c:string" xmlns:c="www.w3.org/.../XMLSchema&quot;>Test2</b:value>

             </a:KeyValuePairOfstringanyType>

           </a:Attributes>

           <a:EntityState i:nil="true" />

           <a:FormattedValues xmlns:b="schemas.datacontract.org/.../System.Collections.Generic&quot; />

           <a:Id>00000000-0000-0000-0000-000000000000</a:Id>

           <a:LogicalName>contact</a:LogicalName>

           <a:RelatedEntities xmlns:b="schemas.datacontract.org/.../System.Collections.Generic&quot; />

         </entity>

       </Create>

     </s:Body>

    </s:Envelope>

    --------------------------------------------------

    HTTP RESPONSE

    --------------------------------------------------

    <s:Envelope xmlns:s="schemas.xmlsoap.org/.../&quot;>

     <s:Body>

       <CreateResponse xmlns="schemas.microsoft.com/.../Services&quot; xmlns:i="www.w3.org/.../XMLSchema-instance&quot;>

         <CreateResult>ced40971-7634-e611-80ef-c4346bdd9111</CreateResult>

       </CreateResponse>

     </s:Body>

    </s:Envelope>

    --------------------------------------------------

    Above is generated from SOAP Logger application of SDK.

    You may plan to customize it for your call.

    Hope this helps!!

    Mark this question as answered, If you get answer to your question :)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans