cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
funkeke
Frequent Visitor

Make leaving a note on the time line required to save

I have a model-driven app for dataverse. I have a business requirement that the user must leave a comment each time they make an edit to a record. The whole comment history should be available when viewing that record. I wanted to use the Timeline control to do this since it looks nice, supports attachments, is highly functional, and meets all my needs already other than needing the comment to be required.

 

Is it possible to make adding a note to the timeline required in order for the record to be saved? I could probably use the client API to do something onSave of the form with JavaScript, such as block submit if a note hasn't been added, and display a dialog. But that is really inelegant and not a good user experience. Any ideas?

2 ACCEPTED SOLUTIONS

Accepted Solutions
skoofy5
Advocate IV
Advocate IV

I think you're close - this works for me:


record["objectid_account@odata.bind"] = "/accounts(7e77b79a-6569-e568-c960-d2ffff0dd8f2)";

 

var record = {};
record["objectid_account@odata.bind"] = "/accounts(7e77b79a-6569-e568-c960-d2ffff0dd8f2)"; // Lookup
record.subject = "TEST"; // Text

Xrm.WebApi.online.createRecord("annotation", record).then(
	function success(result) {
		var newId = result.id;
		console.log(newId);
	},
	function(error) {
		console.log(error.message);
	}
);

 
"Dataverse REST Builder" is now available in xrmtoolbox which can help you craft simple requests like this.

View solution in original post

funkeke
Frequent Visitor

Brilliant! Thank you for suggesting the Dataverse REST Builder - it was easy to setup and use as part of XrmToolBox. It helped me see exactly what my odata values needed to be for this polymorphic lookup.

 

In my case I am trying to save a note for a custom table I created, so the name of it follows the pattern "ab123_donut". Therefore my code needed to be the below. Note that the plural form of the table name must be used on the right side of the odata declaration but on the left side it should be the singular form. I also learned how to refresh the timeline control so the new note shows up right away.

 

 

var data = {};
data['objectid_ab123_donut@odata.bind'] = '/ab123_donuts(' + recordId + ')';
data.subject = commentsVal;
            
Xrm.WebApi.createRecord('annotation', data).then(function success(result) {

    //Refresh the timeline control to show the new comment right away
    formContext.getControl(timelineControlName).refresh();
},
function (error) {
    console.log(error.message);
});

 

 

View solution in original post

4 REPLIES 4
funkeke
Frequent Visitor

I figured I could make a separate required comments field and, using the client API, on postSave create a new Note. But I'm struggling to create the note record with the createRecord client API method.

 

I can create a basic note, I am able to set the "subject" of the note fine. The ID of my new record is available as expected too. But my challenge is associating the Note with my new record. I know I have to use the "odata.bind" syntax because Notes has a polymorphic relationship with other tables, but something isn't right. 

 

Below is my code. I am getting the error "An undeclared property 'objectid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values." --- But "objectid" is the logical name of the lookup column on the Notes table.

 

I am struggling to understand what value to use for "my_table_name" due to poor documentation - should it be the logical name of my table? The schema name? Or should it be the relationship name?

 

 

 

var data = {
    'objectid@odata.bind': '/my_table_name(' + newRecordId + ')',
    subject: commentsVal
};
            
Xrm.WebApi.createRecord('annotation', data).then(successCallback, errorCallback);

 

 

 

I'm wondering if I need to declare the relationship to the Notes table myself for this to work. The current relationship to Notes was made automatically.

skoofy5
Advocate IV
Advocate IV

I think you're close - this works for me:


record["objectid_account@odata.bind"] = "/accounts(7e77b79a-6569-e568-c960-d2ffff0dd8f2)";

 

var record = {};
record["objectid_account@odata.bind"] = "/accounts(7e77b79a-6569-e568-c960-d2ffff0dd8f2)"; // Lookup
record.subject = "TEST"; // Text

Xrm.WebApi.online.createRecord("annotation", record).then(
	function success(result) {
		var newId = result.id;
		console.log(newId);
	},
	function(error) {
		console.log(error.message);
	}
);

 
"Dataverse REST Builder" is now available in xrmtoolbox which can help you craft simple requests like this.

I think your approach is great - using an 'edit comments' field and making it required and empty when the form loads then on save just move it to the timeline as a note. It definitely feels like it would be the most straightforward.

funkeke
Frequent Visitor

Brilliant! Thank you for suggesting the Dataverse REST Builder - it was easy to setup and use as part of XrmToolBox. It helped me see exactly what my odata values needed to be for this polymorphic lookup.

 

In my case I am trying to save a note for a custom table I created, so the name of it follows the pattern "ab123_donut". Therefore my code needed to be the below. Note that the plural form of the table name must be used on the right side of the odata declaration but on the left side it should be the singular form. I also learned how to refresh the timeline control so the new note shows up right away.

 

 

var data = {};
data['objectid_ab123_donut@odata.bind'] = '/ab123_donuts(' + recordId + ')';
data.subject = commentsVal;
            
Xrm.WebApi.createRecord('annotation', data).then(function success(result) {

    //Refresh the timeline control to show the new comment right away
    formContext.getControl(timelineControlName).refresh();
},
function (error) {
    console.log(error.message);
});

 

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (2,099)