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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Reg Selecting Two Option set Create Task in Timeline

(0) ShareShare
ReportReport
Posted on by 25

Hi I have a Question

How to Create a Task in Timeline upon Selection on Two Option Set "Yes" 

Is there a way by Javascript or Workflow will Help 

Please let me know, thanks in advance 

Scinario --- 

I have Two Options field 

and I want after selecting Yes a New Task Should be created .

Thank You

I have the same question (0)
  • Suggested answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at

    Hi,

    You can achieve same using JavaScript and in JavaScript add condition to check the two option set field value if it is yes then run below code.

    // define the data 
    var data =
        {
            "subject": "Sample task",
            "description": "Some sample data",
            "regardingobjectid_opportunity@odata.bind":"/opportunities(GUID)"
        }
    
    // create account record
    Xrm.WebApi.createRecord("task", data).then(
        function success(result) {
            console.log("Task created with ID: "   result.id);
            // perform operations on record creation
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );

    When we set the regarding object id value then task will automatically appear in Timeline for respective entity as shown below:

    pastedimage1632290608437v1.png

    You can achieve same by using Workflow:
    In workflow tick the Field Change and Record Created property and add Check condition if two option set  field value is yes then create task as shown below:

    pastedimage1632290246784v1.png


    same functionality you can achieve through plugin as well as Power Automate.

    Thanks,

    Pradeep.

    Please mark this as VERIFIED it it helps.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi Sid Desh,

    You could create a on change event on your Two Options field with the following code(My regarding type is account):

    function addTaskOnChange(executionContext){
    	var formContext = executionContext.getFormContext();
    	var optionValue = formContext.getAttribute("new_addtask").getValue();
    	var accountId = formContext.data.entity.getId().replace("{","").replace("}","");
    	if(optionValue){
    		var data = {};
    		data.subject = "My New Task";
    		data["regardingobjectid_account@odata.bind"] = "/accounts("   accountId   ")";
    		Xrm.WebApi.createRecord("task", data).then(
    			function success(result){
    				// refresh timeline
    				formContext.getControl("Timeline").refresh();
    				// do something
    			}, 
    			function fail(error){
    				console.log(error.message);
    			}
    		);
    	}
    }

    Result:

    pastedimage1632292822050v2.png

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Hamza H Profile Picture

Hamza H 140 Super User 2026 Season 1

#2
Nagaraju_Matta Profile Picture

Nagaraju_Matta 128

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 70 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans