Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Reg Selecting Two Option set Create Task in Timeline

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

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Reg Selecting Two Option set Create Task in Timeline

    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

  • Suggested answer
    Pradeep Rai Profile Picture
    Pradeep Rai 5,490 Super User 2024 Season 2 on at
    RE: Reg Selecting Two Option set Create Task in Timeline

    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.

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,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans