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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

AutoPopulate Phone number on phone call activity

(0) ShareShare
ReportReport
Posted on by 155

How can we auto populate phone number field on phone call activity from contact/account (Other than Javascript or Plugin)??

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    It depends on when you want the phone number to be populated and from which contact or account you want the phone number to be populated

    If you want the phone number to be poplated as soon as the Call To set, you can use javascript to populated the phone number but having a plugin or custom workflow activity on Workflow (possibly realtime workflow ) would be much better as it could work even for the import or if its created by other clients.

    One other thing to consider, is you may have to populate more than one phone number, if the contact has home and mobile or workphone you will have to have comma seperated list of phone numbers in the phone number field.

    Let me know if you need any sample code for doing it as plugin or CWA

  • Itz_Me_Ram Profile Picture
    155 on at

    Thank you Kokulan. Please send me the sample code if you already have.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi

    Please have a look at my example on github

    github.com/.../PopulatePhoneNumberOnPhoneCall.cs

    You will have to call this CWA on a workflow (a real-time workflow is better) whenever a phone call record is created or whenever the To field changes

    Hope this helps

  • Suggested answer
    Alok Singh Profile Picture
    910 on at

    Hi ,

    You can user real time workflow to auto populate phone number from Account or Contact on creation of Phone call.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi

    you can use below code to acheive it.

    1680.9.PNG

    For Account

    5700.8.PNG

    For Contact

    6866.7.PNG

    function getphonecall(executionContext)
    {
     var formContext = executionContext.getFormContext();
     if(formContext.getAttribute("to").getValue() != null) 
     {
    		var entity = formContext.getAttribute("to").getValue()[0].entityType;
    		var id = formContext.getAttribute("to").getValue()[0].id;
    		   id = id.replace("{", "").replace("}", "");
            var query ;
    		
    		if(entity == "account")
    		{
    		   query = "/api/data/v9.1/accounts("+id+")?$select=telephone1"; // remember to change v9.1 to your correct version, i am using telephone1, if you are using other field, please change it accordingly
    		
    		}
    		
    		else if (entity == "contact")
    		{
    		  query = "/api/data/v9.1/contacts("+id+")?$select=telephone1";// remember to change v9.1 to your correct version, i am using telephone1, if you are using other field, please change it accordingly
    		}
    		
    		var req = new XMLHttpRequest();
    		req.open("GET", Xrm.Page.context.getClientUrl()+query,true);
    		req.setRequestHeader("OData-MaxVersion", "4.0");
    		req.setRequestHeader("OData-Version", "4.0");
    		req.setRequestHeader("Accept", "application/json");
    		req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    		req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    		req.onreadystatechange = function() {
    			if (this.readyState === 4) {
    				req.onreadystatechange = null;
    				if (this.status === 200) {
    					var result = JSON.parse(this.response);
    					var telephone1 = result["telephone1"];
    					formContext.getAttribute("phonenumber").setValue(telephone1);// i am using telephone1, if you are using other field, please change it accordingly
    				} else {
    					Xrm.Utility.alertDialog(this.statusText);
    				}
    			}
    		};
    		req.send();
    }
    
    }


    I register above JS on "Call TO " , you also can imporve the JS to do more checking.

    1680.9.PNG

    6471.10.PNG

  • Community Member Profile Picture
    on at

    you can use the javascript to populate the phone number by having custom workflow  activity on workflow possibly real time,.

  • Community Member Profile Picture
    on at

    Hello Wei,

    Thank you for the solution. I am however facing a few issues with it:

    1. When I open the phone call activity, the phone is not pre-populated. I have to remove the already pre-added contact and add it again. Is it possible to change that?

    2. Also, when I remove the contact, an error message is generated. Why do you suppose this is happening? Here is the error message:

    TypeError: Cannot read property 'entityType' of undefined

       at getphonecall (sentiadev.crm4.dynamics.com/.../sen_phonenumbercopy:6:60)

       at mp.executeFunction (sentiadev.crm4.dynamics.com/.../app.js

       at mp.execute (sentiadev.crm4.dynamics.com/.../app.js

       at up._executeIndividualEvent (sentiadev.crm4.dynamics.com/.../app.js

       at up._executeEventHandler (sentiadev.crm4.dynamics.com/.../app.js

       at Object.execute (sentiadev.crm4.dynamics.com/.../app.js

       at O._executeSyncAction (sentiadev.crm4.dynamics.com/.../app.js

       at O._executeSync (sentiadev.crm4.dynamics.com/.../app.js

       at O.executeAction (sentiadev.crm4.dynamics.com/.../app.js

       at t.dispatch (sentiadev.crm4.dynamics.com/.../app.js

    Thanks for your help!

    Regards,

    Georgi

  • Community Member Profile Picture
    on at

    Hello Wei,

    Thank you for the solution. I am however facing a few issues with it:

    1. When I open the phone call activity, the phone is not pre-populated. I have to remove the already pre-added contact and add it again. Is it possible to change that?

    pastedimage1586521759754v1.png

    2. Also, when I remove the contact, an error message is generated. Why do you suppose this is happening?

    pastedimage1586521818634v2.png

    Here is the error message:

    TypeError: Cannot read property 'entityType' of undefined

       at getphonecall (sentiadev.crm4.dynamics.com/.../sen_phonenumbercopy:6:60)

       at mp.executeFunction (sentiadev.crm4.dynamics.com/.../app.js

       at mp.execute (sentiadev.crm4.dynamics.com/.../app.js

       at up._executeIndividualEvent (sentiadev.crm4.dynamics.com/.../app.js

       at up._executeEventHandler (sentiadev.crm4.dynamics.com/.../app.js

       at Object.execute (sentiadev.crm4.dynamics.com/.../app.js

       at O._executeSyncAction (sentiadev.crm4.dynamics.com/.../app.js

       at O._executeSync (sentiadev.crm4.dynamics.com/.../app.js

       at O.executeAction (sentiadev.crm4.dynamics.com/.../app.js

       at t.dispatch (sentiadev.crm4.dynamics.com/.../app.js

    Thanks for your help!

    Regards,

    Georgi

  • RickPagliarulo Profile Picture
    5 on at

    Hi Georgi,

    For question #1 - It might work if you configure the script to run OnLoad, as well (from what I can see based on Wei's instructions, it looks like the script it firing OnChange of that "Call To" field.  I am not sure how it will behave when creating a new record, but you could try to have the script run when the form loads as well, instead of just when that specific "Call To" field changes.

    As for question #2, I think the error may be occurring because the script is running when the "Call To" field changes.  Since your process is currently to clear out that Call To field, and then fill it back in, you are changing the field twice.  The first time the script runs is when you clear out the "Call To" field -- at this point the script is trying to read and execute actions based on a blank value -- hence the message "cannot read property EntityType of undefined."  Maybe you can add a condition to the beginning of the script, that says to only carry out an action if the "Call To" field contains data.

    I hope this helps!  My experience with javascript web resources is pretty limited, but I've run into these same types of issues in the past, so I think the answers above do address your questions.

  • Suggested answer
    Kumar Viju Profile Picture
    1,026 on at

    Assumption 1: If you are going to create Phone Call from Account UCI (Timeline)

    (No Code Approach)

    a. Create a custom N:1 Relationship between Account and Phone Call using Phone Call Activity ( OOB Relation will not work as it is managed to add any mappings. I doubt even if it has mapping label)

    b. Add mapping between Primary Phone and the Phone Number

    (Code Approach)

    Refer to this blog to get the basics of retrieving values using JScript and WebApi. It will help you, in the long run, to perform and type of queries.

    arunpotti.com/.../

    Advice:

    1. Avoid using traditional\custom workflow for any of your business needs if you are in Cloud and use PowerAtumate(Flow) to have a stable long term solution. Workflows are soon to be deprecated!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Liquid error: parsing "/globalsearch/?q=Independiente+0+%3A+2+Boca+Juniors++tarjetas" - Nested quantifier +.