Reputation: 1059
Our client wants a TrueFalse property on a document type to be automatically and dynamically set to a value, based on the value of two number fields on an entity in Dyanamics CRM.
The current workaround used, is to just manually set the value in Umbraco Backoffice whenever it is needed.
The solution already contains a connection to the Dynamics CRM database and has access to a view that contains the correct boolean value to be used via Entity Framework in the backend.
Each page using the document type is connected to an "Event" via an Id. This event is also represented by an entity in Dynamics CRM. It is via this Id, that the boolean value should be set on the property.
Is it possible to dynamically set the value of a TrueFalse property on a document type, while also making it read-only for the user? The value should be updated ideally every 5 minutes or less.
Upvotes: 0
Views: 215
Reputation: 1781
In order to display read-only data in the Umbraco backoffice, here are the steps that you should follow;
Integrate your CRM with Umbraco, using a service like Azure Service Bus or something similar. I understand you already have some kind of connection between your CRM and CMS using a unique Event Id; use this value to dynamically get your Umbraco content and set the value of your new Label property. You will need to use Umbraco's ContentService for getting and setting the Umbraco content data.
If your label's value type is String, then you can set its value to True or False, or 1 or 0. If you label's value type is Integer, then you can set its value to 1 or 0.
Some code examples;
Dependency Injection for Umbraco v8's ContentService
public class MyClass
{
private readonly IContentService _contentService;
public MyClass(IContentService contentService)
{
_contentService = contentService;
}
}
If you wish to use the content service in a class that inherits from one of the Umbraco base classes (eg. SurfaceController, UmbracoApiController or UmbracoAuthorizedApiController), you can access the content service through a local Services property:
IContentService contentService = Services.ContentService;
Creating content programmatically using the Content Service
// Get access to ContentService
var contentService = Services.ContentService;
// Create a variable for the GUID of the parent where you want to add a child item.
// In this case the people page.
var parentId = Guid.Parse("b6fbbb31-a77f-4f9c-85f7-2dc4835c7f31");
// Create a new child item of type 'person'
var person = contentService.Create("James", parentId, "person");
// Set the value of the property with alias 'email'
person.SetValue("email" , "[email protected]");
// Set the value of the property with alias 'isAuthor'
person.SetValue("isAuthor", false);
// Save the child item
contentService.Save(person);
Upvotes: 0
Reputation: 1
Upvotes: 0