I was trying to refresh the a model so that it will include the newly created record that i created, but When i checked, the query of the model that i refreshed using model.updateData() didn’t change.
var field = argumentst0], value = argumentse1],
newDocumentLink=‘’,
firstRecord = ‘’;
var linkModel = skuid.model.getModel(‘NewContentLink’);
var noteModel = skuid.model.getModel(‘ContentNote’);
var refreshContentDocumentLink = skuid.model.getModel(‘ContentDocumentLink’);
var refreshContentVersion = skuid.model.getModel(‘ContentVersion’);
var activeContact = skuid.model.getModel(‘SelectedContact’);
var activeAccount = skuid.model.getModel(‘SelectedAccount’);
var newContentNote = noteModel.getFirstRow();
var contentLinkCondition = refreshContentDocumentLink.getConditionByName(‘Link’);
var contentVersionCondition = refreshContentVersion.getConditionByName(‘ContentDocumentID’);
if(activeContact.data.length !== 0){
firstRecord=activeContact.getFirstRow();
}
else{
firstRecord=activeAccount.getFirstRow();
}
noteModel.updateRow({ Id:newContentNote.Id },{
IsDeleted: false,
Content: btoa(newContentNote.Content),
FileType:‘SNOTE’
});
noteModel.save({callback: function(result){
if (result.totalsuccess) {
//creating a new link
newDocumentLink = linkModel.createRow({
additionalConditions: D
{ field: ‘ContentDocumentId’, value: newContentNote.Id},
{ field: ‘LinkedEntityId’, value: firstRecord.Id},
{ field: ‘ShareType’, value: ‘V’},
{ field: ‘IsDeleted’, value: false},
{ field: ‘Visibility’, value: ‘AllUsers’}
], doAppend: false
});
//saving changes on the model. hence the new link
linkModel.save({callback: function(result){
if (result.totalsuccess) {
// empties these model so that it won’t take space in the long run
noteModel.emptyData();
linkModel.emptyData();
//refresh the model ContentDocumentLink
refreshContentDocumentLink.setCondition(contentLinkCondition,firstRecord.Id,false);
refreshContentDocumentLink.updateData();
} else {
console.log(result.insertResults);
console.log(result.updateResults);
console.log(result.deleteResults);
}
}});
} else {
console.log(result.insertResults);
console.log(result.updateResults);
console.log(result.deleteResults);
}
}});
//refresh the model contentVersion
refreshContentVersion.activateCondition(contentVersionCondition,false);
refreshContentVersion.updateData();
Found out why…
refreshing of the model should be inside the callback of the refreshing of the contentLink
//saving changes on the model. hence the new link
linkModel.save({callback: function(result){
if (result.totalsuccess) {
// empty these models, might take up space
noteModel.emptyData();
linkModel.emptyData();
//refresh the models ContentVersion and ContentLink
refreshContentDocumentLink.setCondition(contentLinkCondition,firstRecord.Id,false);
refreshContentDocumentLink.updateData(function(){
refreshContentVersion.activateCondition(contentVersionCondition,false);
refreshContentVersion.updateData();
});
} else {
console.log(result.insertResults);
console.log(result.updateResults);
console.log(result.deleteResults);
}
}});
Glad you got it working!
Lorenz~
Sorry this was frustrating you. Glad you figured out what was wrong!
Thanks for sharing your solution with the community.
Karen
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.