1
votes

I have written the below function :

function openConnectionForm() {
    "use strict";
    var parameters = {};
    var id = Xrm.Page.data.entity.getId();
    id = id.substr(1);
    id = id.slice(0,-1);
    parameters["record1id"] = id;
    alert(id);
        var entityName = "connection";
        var windowOptions = {
            openInNewWindow: true
        };
        Xrm.Utility.openEntityForm(entityName, null, parameters, windowOptions);

}

I have a ribbon button "Connect". When I click that button, I want to open Connections form and I want to pre populate the field "record1id" with the guid of the record on which I click the ribbon button.

The form is opening on clicking the ribbon button. But, the field "record1id" is not populated as expected. Some garbage guid is added.

What am I doing wrong?

Update :

I have changed the code to :

var id = Xrm.Page.data.entity.getId();
var name = Xrm.Page.getAttribute("fullname").getValue();
alert(id);
alert(name);

var parameters = {};
parameters["record1id"] = id;
parameters["record1idname"] = name;


var entityName = "connection";
var windowOptions = {
    openInNewWindow: true
};
alert("Done");
Xrm.Utility.openEntityForm(entityName, null, parameters, windowOptions);
alert("Form Opened");

The form is opening.

enter image description here

But, when I click on the contact, I get this : enter image description here

2

2 Answers

0
votes

It looks like you may need to pass three pieces to the parameter. See here.

Example (untested)

parameters["record1id"] = [{
    "entityType": "contact",
    "id": id,
    "name": "John Smith"
}]

Working Code I've used

var systemUserObject = [{
    "entityType": "SystemUser"
    , "id": this.currentUser.SystemUserId.Value.id
    , "name": this.currentUser.LastName.Value + ", " + this.currentUser.FirstName.Value
}];

Xrm.Page.getAttribute("ccseq_leaduserid").setValue(systemUserObject);
0
votes

If I understand correctly, you are trying to populate the record1id lookup in Connection entity form when it’s opened from custom ribbon button ‘Connect’. Then you have to mimic the following OOB behavior.

By OOB, when you click Connect to Another the Connection form will get Connected From lookup prepopulated by current record. Same way when clicking Connect to Me will prepopulate both From & To (record1id & record2id) with current record & current login user respectively.

enter image description here

Referring record1id from MS documentation it’s identical to regardingobjectid lookup & MS says it’s not possible to set regarding lookup value.

You can’t set the values for partylist or regarding lookups.