Monthly Archives: February 2014

Autopopulate Activity Party Using Query String

In the target form properties we have set up 2 parameters . Every Parameter needs to have a _ in its name.

  • lema_ciname — Type string
  • lema_ciguid — Type uniqid

Then we can call that form from any external application with :

// Type can be CI Action 919780000 && CI Intruction 919780001
function OpenTaskCreation(CIGuid, CIName,Type) {

    var features = "location=no,menubar=no,status=no,toolbar=no,resizable=yes";

    //Encode Guid of regardingObject to set -- lema_ciname , lema_ciguid
    var extraqs = "lema_ciname=" + CIName;
    extraqs += "&lema_ciguid=" + CIGuid;
    extraqs += "&epa_tasktype=" + Type;

    var features = "location=no,menubar=no,status=no,toolbar=no";

    var serverurl = "http://serverrurl/org";
     // Open the window.
     window.open( serverurl + "/main.aspx?etn=task&pagetype=entityrecord&extraqs=" +
     encodeURIComponent(extraqs), "_blank", features, false);

}

Then, in the form that we are calling we register a js function on the onload event.


function OnSiteVisitTaskLoad() {
    var urlParams = Xrm.Page.context.getQueryStringParameters();
    var ciname = urlParams['lema_ciname'];
    var ciguid = urlParams['lema_ciguid'];

    var partlistData = new Array();
        partlistData[0] = new Object();
        partlistData[0].id = ciguid;
        partlistData[0].name = ciname;
        partlistData[0].entityType = "epa_complianceinvestigation";
        Xrm.Page.getAttribute("regardingobjectid").setValue(partlistData);

    }

This is creation of parameters is only needed to autopopulate Activity parties. For other fields we could use something like.


function OpenNCCreation(LicenceGuid, LicenceName) {

    //Set the values of epa_licenceid field.
    var extraqs = "epa_licenceid={" + LicenceGuid + "}";
    extraqs += "&epa_licenceidname=" + LicenceName;

    var features = "location=no,menubar=no,status=no,toolbar=no";
    // Open the window.
    window.open("/main.aspx?etn=epa_noncompliance&pagetype=entityrecord&extraqs=" +
     encodeURIComponent(extraqs), "_blank", features, false);

}

More info about Prepopulating creation forms here or in this Microsoft post.

Advertisements

CRM 2011 Javascript – working with Option sets

If we want to write the value of an option set in a text field.

 
function onyearchange() {
    var myOptionSet = Xrm.Page.data.entity.attributes.get("lema_year");
    var optionSetText = myOptionSet.getText();
    Xrm.Page.getAttribute("lema_name").setValue(optionSetText);
}

If we need to set the value of an option set based on a text

 

function SetOptionSetValueByText(optionsetAttribute, optionText)  
 {  
  var options = Xrm.Page.getAttribute(optionsetAttribute).getOptions();  
  for(i = 0; i < options.length; i++)  
  {  
  if (options[i].text == optionText)  
   Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value);  
  }  
 }  



SetOptionSetValueByText("lema_year","2014");