Joao Leme
Joao Leme

Reputation: 9888

passing dynamic parameter (field values) to webresource on Dynamics CRM using custom parameter (data)

Can't get the values into the querystring of the webresource iframe url. I add the field name (schema name) to the custom parameter (data) and get the field name on the querystring (static) and not the field value.

Upvotes: 2

Views: 7027

Answers (2)

Joao Leme
Joao Leme

Reputation: 9888

Even though there are posts saying you can pass dynamic values to the custom parameter (data) of the webresource, my experience is the same as Adi's above, that those parameter are only for static values.

In that case the easiest alternative I found to get the values of the form fields into the webresource are even simpler than what I was trying to do. By just adding: window.parent. you get access to Xrm.Page. So all you have to do is:

var formfieldValue = window.parent.Xrm.Page.getAttribute("CRMFieldSchemaName").getValue();

Don't forget to place it within a javascript tag on the webresource:

<script type="text/javascript">
  $(function () {
     var formfieldValue = window.parent.Xrm.Page.getAttribute("CRMFieldSchemaName").getValue();
  });
</script>

Upvotes: 2

Adi Katz
Adi Katz

Reputation: 548

That box is for static values. To make it dynamic you need to construct the IFRAME URL using Javascript.

I used XrmIframe as framework in order to make Iframe coding simple. The important part happens in the OnLoad Event.

Keep in mind that this is just a basic example.

//SDK Iframe helper example
function XrmIframe(sId) {
    if (sId == undefined) return;

    var xiObject = this;
    xiObject.Ctl = Xrm.Page.getControl(sId);

    xiObject.Get = function () { 
        return xiObject.Ctl.getSrc(); 
    }

    xiObject.Set = function (sUrl) { 
        xiObject.Ctl.setSrc(sUrl); 
        return xiObject; 
    }               
}

//entity onload js
var myIframe;
function OnLoad() {
    //construct iframe
    myIframe = new XrmIframe("IFRAME_Test");
    //load iframe
    myIframe.Set("construct url with dynamic values here...")
}

Upvotes: 0

Related Questions