Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Store value in custom field in phone call activity entity

Posted on by Microsoft Employee

Hi experts,

I have used custom scripting to create a custom phone call activity onSave of form. I am trying to set value of new_timer into a a custom field I have created in phone call activity form but it is not setting the value. 

/*This function will help to create PhoneCall Activity entity Record*/

function TaskCreation()
{
	
	//get Current Logged in User name
	var UserName=Xrm.Page.context.getUserName();
	
	//get Logged is user GUID
	var UserId=Xrm.Page.data.entity.getId();
	
	//Get Current timer value
	var TimerValue = Xrm.Page.getAttribute("new_timer").getValue();
	
	//Get Current Computer Time
	var CurrentTime = Xrm.Page.getAttribute("new_currenttime").getValue();
	
	//Get Primary Contact
	var con = Xrm.Page.getAttribute("customerid").getValue();

	
	//Set Task Activity Entity record
	var Task = {};
	Task.Subject = "Call Timing of User "+UserName; //set task subject
	Task.Description = "Call Running Time: "+TimerValue+"\nUser Name: "+UserName+"\nCall date: "+CurrentTime; //set Task Description
        Task.Description.new_duration = "TimerValue"; //set Task Duration
	Task.RegardingObjectId = { Id: Xrm.Page.data.entity.getId(), LogicalName: 'incident'}; //set parent entity type
	
	
	var activityParties = new Array();
	
	var partyObj0 = new Object();
	partyObj0.PartyId = { Id: con[0].id, LogicalName: con[0].entityType };
	partyObj0.ParticipationTypeMask = { Value: 1 }; //Setting "From" of Phonecall
	activityParties[0] = partyObj0;
	
	var partyObj1 = new Object();
	partyObj1.PartyId = { Id: con[0].id, LogicalName: con[0].entityType };
	partyObj1.ParticipationTypeMask = { Value: 2 }; //Setting "To" of PhoneCall
	activityParties[1] = partyObj1;
	
	Task.phonecall_activity_parties = activityParties;  //set activityParties
	
	
	//finally create Task
	SDK.REST.createRecord(Task,"PhoneCall",
	function (Task)
	{
		writeMessage("The phonecall with Subject \"" + Task.Subject + "\" was created");
	},errorHandler);
	
	//Error handling
	function errorHandler(error)
	{
		writeMessage(error.message);
	}
}



I am trying to store TimerValue from case record into new_duration field in phone call record but it it not setting. Please see code in pink

Thanks,

Jon

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store value in custom field in phone call activity entity

    Thanks guys! That worked.

  • Verified answer
    Nitin Meria Profile Picture
    Nitin Meria 216 on at
    RE: Store value in custom field in phone call activity entity

    Hi Jon,

    Specify value for new_duration using :

    Task.new_duration = "TimerValue"; //set Task Duration

     

    Also, you are not referencing the correct userID in your code. You need to use :

    var UserId=Xrm.Page.context.getUserId();

  • Verified answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Store value in custom field in phone call activity entity

    Hi Jon,

    Please replace the code in your question as

    Task.new_duration = TimerValue; //set Task Duration

    instead of

    Task.Description.new_duration = "TimerValue"; //set Task Duration

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store value in custom field in phone call activity entity

    Hi Nithya,

    I am not looking to fetch the data from from case record. I would like to populate the field at the time of save on case record.

    For example, I am viewing a case record and made some changes. Now, when I click save, my script above gets triggered and creates a new phone call activity. In this same script I would like the new_duration field also to get populated with value TimerValue.

    Thanks,

    Jon

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Store value in custom field in phone call activity entity

    Hi Jon,

    Try the code below on save of the phone call form.

    function GetTimerFromCase() {
        var regarding = Xrm.Page.getAttribute("regardingobjectid");
        if (regarding != null) {
            var regardingValue = regarding.getValue();
            if (regardingValue != null) {
                var regardingEntityType = regardingValue[0].entityType;
                if (regardingEntityType == "incident") {
                    var regardingId = regardingValue[0].id.replace('{', '').replace('}', '');
                    var req = new XMLHttpRequest();
                    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/incidents(" + regardingId + ")?$select=new_timer", 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.onreadystatechange = function () {
                        if (this.readyState === 4) {
                            req.onreadystatechange = null;
                            if (this.status === 200) {
                                var result = JSON.parse(this.response);
                                var timer = result["new_timer"];
                                Xrm.Page.getAttribute("new_duration").setValue(timer);
                            }
                            else {
                                alert(this.statusText);
                            }
                        }
                    };
                    req.send();
                }
            }
        }
    }

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store value in custom field in phone call activity entity

    Xrm.Page.getAttribute("new_duration").setValue(TimerValue);

    I tried the above but it gives me same error as above.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store value in custom field in phone call activity entity

    Hi Nithya,

    The data type is single line of text. 

    The field new_timer is in the case form. When I click save button to create a phone call activity, I would like this value from the new_timer field to be copied to field new_duration in phone call entity form.

    Thanks,

    Jon

  • Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Store value in custom field in phone call activity entity

    Hi Jon,

    What is the datatype of the field new_timer? Is the field new_time added to the custom phone call entity form? If not, add it to the form and try setting the value using the code below.

    Xrm.Page.getAttribute("new_time").setValue(TimerValue);

    Hope this helps.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Store value in custom field in phone call activity entity

    I even tried:

           Xrm.Page.getAttribute("new_duration").setValue(TimerValue);

    but i get error:

    Screen-Shot-2018_2D00_06_2D00_12-at-1.21.47-PM.png

    Thanks,

    Jon

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans