Access Umbraco Content in Custom Umbraco Forms workflow
I am trying to get a custom workflow working where I want to create a node based on a form selection.
I have this code
public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e)
{
record.State = FormState.Approved;
var contentService = Current.Services.ContentService;
var parentNode = Guid.Parse("ff3e93f6-b34f-4664-a08b-d2eae2a0adbd");
var dateField = e.Record.GetRecordFieldByAlias("selectedDate");
var timeField = e.Record.GetRecordFieldByAlias("selectedTime");
var nodeExists = Umbraco.Content(parentNode).DescendantsOfType("appointmentItemDate").Where(x => x.Name == theDate);
var dateItem = contentService.Create(dateField.ValuesAsString(), parentNode, "appointmentItemDate");
contentService.SaveAndPublish(dateItem);
return WorkflowExecutionStatus.Completed;
//Current.Logger.Debug<TimeDateWorkflowType>("The record with unique id {RecordId} that was submitted via the Form {FormName} with id {FormId} has been changed to {RecordState} state",
// record.UniqueId, e.Form.Name, e.Form.Id, "approved");
}
The problem is this one
var nodeExists = Umbraco.Content(parentNode).DescendantsOfType("appointmentItemDate").Where(x => x.Name == theDate);
The type or namespace name 'Content' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
How can I access published nodes in this workflow?
I want to check if there already exists a node with a given name, f.x. "29-05-2021" and then not create a new node with that name.
The error you're getting there is because your custom workflow class doesn't have the UmbracoHelper available (so when calling Umbraco.Content it will throw the error)
You can get a handle on the UmbracoHelper using this code:
var helper = Umbraco.Web.Composing.Current.UmbracoHelper;
and then call this line:
var nodeExists = helper.Content(parentNode).DescendantsOfType("appointmentItemDate").Where(x => x.Name == theDate);
Access Umbraco Content in Custom Umbraco Forms workflow
I am trying to get a custom workflow working where I want to create a node based on a form selection.
I have this code
The problem is this one
The type or namespace name 'Content' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
How can I access published nodes in this workflow?
I want to check if there already exists a node with a given name, f.x. "29-05-2021" and then not create a new node with that name.
Hi Morten,
The error you're getting there is because your custom workflow class doesn't have the UmbracoHelper available (so when calling Umbraco.Content it will throw the error)
You can get a handle on the UmbracoHelper using this code:
and then call this line:
Hope that helps!
That works perfectly! :)
Thanks alot!
is working on a reply...