RE: Pull the phone number
Hi,
From which contact phone number field do you want to populate the phone number field?
The field can be populated when creating the phone call or when loading it with JS.
- Creating (from contact)
With Xrm.Navigation.openForm(), you can open a quick create form and set the phonenumber from the contact.
Example:
Xrm.Navigation.openForm(
{
entityName: "phonecall",
useQuickCreateForm: true,
createFromEntity: {
entityType: "contact",
id: "00000000-0000-0000-0000-000000000000"
}
},
{
phoneNumber: "555 555 5555"
}
);
- Loading
You can set the phonenumber by doing a request to WebApi with Xrm.WebApi.retrieveRecord(), then set the field value.
Example:
async function onFormLoad(execCtx) {
const formCtx = execCtx.getFormContext();
const toAttr = formCtx.getAttribute("to");
const toLookupValue = toAttr.getValue();
if (toLookupValue == null) {
Xrm.Navigation.openAlert({ text: "To field not set" });
return;
}
if (toLookupValue[0].entityType !== "contact") {
Xrm.Navigation.openAlert({ text: "To is not a contact" });
return;
}
const contactId = toLookupValue[0].id;
const result = await Xrm.WebApi.retrieveRecord("contact", contactId, "?$select=telephone1");
const telephone = result.telephone1;
formCtx.getAttribute("phonenumber").setValue(telephone);
}