Set InArgument when launching a workflow programmatically - c#

Is there any way to set the value of a workflow's InArgument parameter from another workflow when launching it programmatically ?
Here's how I launch it:
var req = new ExecuteWorkflowRequest { WorkflowId = new Guid(WorkflowGuids.RenewalWorkflowId), EntityId = theContact.Id };
service.Execute(req);
I can catch the EntityId value back in the other workflow in context.PrimaryEntityId but I am at a loss as to how to populated the arguments and retrieve them on the other side.
Is this possible ? Thanks.

InArgument are defined at step level, not at workflow level.
When a workflow is executed (by a trigger, on-demand or by code) you have the record Id.
You can create a custom workflow activity to fetch other data related (or not connected at all) with your record Id and make it as OutArgument so will be available as input for the InArgument you want to set.

Related

Starting an Elsa workflow from a Workflow model in a controller

I am planning to use Elsa workflow for an enterprise application with acceptance flow (State machine). I am not sure about this process:
I have multiple workflow models designed by admin user. Each is related to a different entity. Now in the corresponding api controller I want to start a workflow for the entity.
The question is which libraries to inject to controller and use to create and instance and get the created instance id?
i.e.
public async Task<IActionResult> StartFlowOfSomeEntity(int entityID)
{
//Is it the right way to load registry?
var registeryList = await _workflowRegistry.ListAsync(CancellationToken.None);
var relatedRegistery = registeryList.FirstOrDefault(uu => uu.Name == "MyFlowName");
//Now need to create new instance?
}
I am using UpdateInputAsync of WorkflowStorageService to apply outputs to the workflow instance.
I tried to use IWorkflowInstanceStore as sugested here but could not achieve the goal
WorkflowRegistery is the right way to load models. But I prefer to use another method of it:
var relatedRegistery = await _workflowRegistry.FindByNameAsync("MyFlowName", VersionOptions.Latest);
For creating workflow instances you should inject WorkflowStarter to your controller and then do this:
RunWorkflowResult workflowInstance = await _wfStarter.StartWorkflowAsync(relatedRegistery , null, null, null, entityID.ToString());
Then workflowInstance.WorkflowInstance.Id has the value of the instance id you want.
You can also see this code at github doing similar thing with Elsa.

How to define your own database ID - Firebase Xamarin

I have the following database:
And I want to use the "Nome" value as an ID instead of a generated code. Instead of -MzKveR8JIXgWsrph_or I wanted it to be Teste1.
My current insert code looks like this:
MyDatabaseRecord databaserecord = new MyDatabaseRecord
{
Nome = EntryNome.Text.ToString(),
Prato1 = EntryPrt1.Text.ToString(),
Prato2 = EntryPrt2.Text.ToString(),
Sopa = EntrySopa.Text.ToString(),
Contacto = EntryContacto.Text.ToString()
};
firebaseClient.Child("Restaurantes").PostAsync(databaserecord);
What do I need to change in order to set the decided value as a Firebase ID? I've been trying to get there but couldn't yet find the right answer.
The Firebase Realtime Database API for C# follow a REST-ful pattern for its method names. This means that calling POST on a URL creates a resource under that location with an identifier determined by the system. If you want to determine your own identifier, call PUT on the entire path (including that identifier).
So:
firebaseClient.Child("Restaurantes/RestaurantOne").PutAsync(databaserecord);

Unexpected Behaviour while trying to update database in consecutive requests - EF 6

I have been dealing with this for days
Summary
I am creating a Social site that will be the back bone for another web application. The hangup is when I submit a request to create a group all goes well, but if I attempt to submit this form again with different data I get a DbEntityValidationException. The exception is related to the ApplicationUser entry.
Details
When I start the Application in Debug mode and submit the Group creation form for the first time it will succeed, adding all the entities into the database as excepted. I have verified this and all looks good. While in the same Debug session, I change the information in the form, to create another group, and submit the form, which leads to the DbEntityValidationException.
The error is related the when I try to insert a SocialGroupMemberModel which contains a reference to the User, and other details related to the users status in the group. The User entry is being marked as added and EntityFramework is trying to insert the User instead of updating. I have attempted to set the Navigation (User) and set the ForeignKey (UserId), both lead to the same error.
I am using HttpContext.Current.GetOwinContext().Get<ApplicationDbContext>();
In the Controller I use ApplicationUserManager to get the User Entity, I then pass this to the Repository to create the group (in either case, either passing the ID, or Entity itself, doesn't work the second time)
Group Creation Code:
var groupInfo = new SocialGroupInfo
{
Created = DateTime.Now,
Description = model.Description,
ShortDescription = model.ShortDescription,
Name = model.Name,
Tags = TagRepo.GetTags(),
Members = new List<SocialGroupMember>()// { member }
};
var groupModel = new SocialGroupModel
{
Slug = model.Slug,
Info = groupInfo
};
Context.SocialGroups.Add(groupModel);
var member = new SocialGroupOwnerModel
{
Joined = DateTime.Now,
UserId = creator
//User = null
//Group = groupInfo
};
groupInfo.Members.Add(member);
//creator.SocialGroups.Add(member);
SaveChanges();
The Validation Error is: "User name ** is already taken" so this leads me to believe that on the second attempt to add the new group, it is attempting to add a new user.
Please ask for any additional information needed, thanks.
This issue was caused by the IoC holding a reference to the previous DbContext, unsure as to why, but removing all usage of Autofac fixed the issue.
Very anticlimactic solution, but issue fixed...
Now the issue is to figure out why Autofac was behaving this way, all Debugging showed that the classes were created each request... but that is another question.

Sitecore:how to get workflow items programmatically

i have assigned workflow as usual. i tried following code but didn't get any item....please share any sample code if you have any or help me get items
Database masterDatabase = Factory.GetDatabase("master");
Item currentItem = masterDatabase.Items["/sitecore/content/Home"];
IWorkflow workflow = masterDatabase.WorkflowProvider.GetWorkflow(currentItem);
WorkflowState state = workflow.GetState(currentItem);
Try to use SecurityDisabler
using (new SecurityDisabler())
{
var db= Factory.GetDatabase("master");
var item = db.Items["/sitecore/content/Home"];
// getting the item's workflow reference
var wf = this.database.WorkflowProvider.GetWorkflow(item);
// here we need either to login as a user with appropriate permissions
// to have access to workflow states/commands or disable security
wf.Start(item);
}
That API is only going to work in a site context where workflow is enabled. Either enable it in your <sites> config or use a context switching block around your code.

Pass Data Between Custom Native Activity in WorkFlow

I'm writing a workflow designer and I want to Send A Data From An Activity To Others without using Inargument on my custom activity so
I write A custom Native Activity and add a property to my context like this
context.Properties.Add("Name",Value );
and for calling the property i use this code:
var dynamicinarg = (string)context.Properties.Find("Name");
but when im Debugging it the dynamicinarg is null .
how can i fix it?

Categories

Resources