open DataReader associated issue - acumatica

I need to release the Production Order Maintenance document from other graph, and when am calling release.press(), am facing data reader issue, can some one please help me, Please have a look at below code
using (new PXConnectionScope())
{
ProdMaintGraph.ProdItemSelected.Current = ProdItem;
ProdMaintGraph.release.Press();
}

You can call the Release(PXAdapter adapter) function!
AMProdItem prodItem = null;//your current record
ProdMaint prodMaint = PXGraph.CreateInstance<ProdMaint>();
prodMaint.ProdMaintRecords.Current =prodMaint.ProdMaintRecords.Search<AMProdItem.orderType, AMProdItem.prodOrdID>(prodItem?.OrderType, prodItem?.ProdOrdID);
var adapterProdMaint = new PXAdapter(prodMaint.ProdMaintRecords, new string[]
{
prodMaint.ProdMaintRecords.Current?.OrderType,
prodMaint.ProdMaintRecords.Current?.ProdOrdID
});
prodMaint.Release(adapter);//Run 'Release Order' action
prodMaint.ReleaseMaterial(adapter);//Run 'Release Material' action

Related

Equivalent of "UserProperties" property in Azure.Messaging.ServiceBus SDK

I am trying to migrate from the Legacy Azure service bus SDK to the new one "Azure.Messaging.ServiceBus". I don't see the equivalent of the "UserProperties" property with the new Azure.Messaging.ServiceBus.ServiceBusMessage. Where can I set the user properties? I see a property called "ApplicationProperties". Is that the one to go for?
Microsoft.Azure.ServiceBus.Message msg = new Microsoft.Azure.ServiceBus.Message(Encoding.UTF8.GetBytes(message.Body));
if (message.Headers != null)
{
foreach (KeyValuePair<string, object> item in message.Headers)
{
msg.UserProperties.Add(item.Key, item.Value); //I need help for this statement.
}
}
Yes, ApplicationProperties is the new custom headers collection to use.

How to prevent global event handlers from firing caused by an API call

I have a custom module that uses Kentico API (DocumentHelper) to update certain fields of my document and then publish but I do not want it to trigger the event handlers that are linked to my document page type. I tried adding comments to .Publish("admin_edit") hoping that I can catch it from the WorkflowEventargs parameter but the VersionComment property always return null. Is there a way to accomplish this in Kentico?
update field:
var document = DocumentHelper.GetDocument(documentID, tree);
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(document);
if (workflow != null)
{
document.CheckOut();
document.SetValue("SomeFIeld", "some value");
document.Update(true);
document.CheckIn();
document.Publish("admin_edit");
}
event handler:
public override void Init()
{
WorkflowEvents.Publish.After += Publish_After;
}
private void Publish_After(object sender, WorkflowEventArgs e)
{
if (!string.IsNullOrEmpty(e.VersionComment) &&
e.VersionComment.Contains("admin_edit"))
return;
}
You always get null for Version information, because that is related to the 'Page versioning' events, specially for 'SaveVersion'. You can find more about that on this link. If you expand 'Properties' you will see which properties are populated for the specific event. In your case, you can try something like this, to add your message for last version and then check for that comment on 'Publish_After' event, see code bellow:
var document = DocumentHelper.GetDocument(documentID, tree);
var workflowManager = WorkflowManager.GetInstance(tree);
var workflow = workflowManager.GetNodeWorkflow(document);
if (workflow != null)
{
document.CheckOut();
document.SetValue("SomeFIeld", "some value");
document.Update(true);
document.CheckIn(versionComment: "admin_edit");
document.Publish();
}
and then, in event handler, take last version and check for comment like this:
if (e.PublishedDocument?.VersionHistory?.Count > 0)
{
var lastVersion = e.PublishedDocument.VersionHistory[0] as VersionHistoryInfo;
if (lastVersion.VersionComment.Equals("admin_edit"))
{
return;
}
}
NOTE: In case that you have a lot of concurrent content editors, there is a chance that your last version is not version from API (someone changed content and saved it right after your API call made change). There is a low chance for that, but still is possible. If this is something that you will use often, you must take it in consideration. This code is tested for Kentico 11.

The file has been modifed by error in sharepoint

I am getting the following error when i try to update the item's name in the sharepoint
document library. The item is of type document set and its default values is loaded using javascript. In the Item added event we are updating with the new changed item's name value. But in the item.update() code statement i am getting following error.
The File CZY14389 has been modified by domain\username on current date.
Please provide your commens on resolving this.
You cannot change the name of a sharepoint document like that. You need to "move it".
Item.Update();
Item.File.MoveTo(Item.ParentList.RootFolder.Url + "/" + newFileName, false);
Item.File.Item["FileRef"] = newFileName;
Item.File.Update();
before you update item name and call item.update(), can you try to refresh your item like this:
item = item.ParentList.GetItemById(item.ID);
item.name = "xyz";
item.update();
this can sometimes happen in event handler. the problem is the updation process in the event handler is not as the same of the workflow. In event handler for updating you have to use the followitn steps. Dont use Item.Update() as in workflow.
Follow the steps:
• call and disable event firing before your code with : base.EventFiringEnabled = false;
•update your item by calling item.systemUpdate(false);
•enable event firing with : base.EventFiringEnabled = true;
Disable event firing and call your update code, dont forget to enable event firing.
HandleEventFiring handleEventFiring = new HandleEventFiring();
handleEventFiring.DisableHandleEventFiring();
try
{
item.Update();
//if item.Update doesnt work then use(For me item.update worked only on my local not on prod then i used the below)
//item.SystemUpdate(false)
}
finally
{
handleEventFiring.EnableHandleEventFiring();
}
public class HandleEventFiring : SPItemEventReceiver
{
public void DisableHandleEventFiring()
{
//obsolete
//this.DisableEventFiring();
this.EventFiringEnabled = false;
}
public void EnableHandleEventFiring()
{
//obsotete
//this.EnableEventFiring();
this.EventFiringEnabled = true;
}
}

Repeated execution of code activity in SharePoint workflow?

I have a custom workflow implementation what requires updation of an external DB. I created a simple workflow for text purpose and found a strange thing!
my Db update/insert code is placed in a code activity of the workflow. it seems the code activity is executed multiple times when the workflow is invoked on a simple list item in sharepoint custom list. Here is my workflow:
and my code is:
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
workflowProperties.Item["Title"] = "Processed by workflow at "+ DateTime.Now;
workflowProperties.Item.Update();
}
private void codeActivity1_ExecuteCode(object sender, EventArgs e)
{
Random rnd = new Random();
string conStr = "Data Source=192.168.1.57\\TRIBIRD;Initial Catalog=XXXXXX;User ID=XXXXXX;Password=XXXXXXXXXX";
SqlConnection connection = new SqlConnection(conStr);
SqlCommand command = connection.CreateCommand();
command.CommandType = System.Data.CommandType.Text;
command.CommandText = "INSERT INTO XXXX VALUES(" + rnd.Next() + ",'THE CONTENT FROM SHAREPOINT WORKFLOW','EN',1,1,'BRT')";
connection.Open();
command.ExecuteNonQuery();
command.Dispose();
connection.Close();
}
in the DB i get more than 1 row for the workflow execution! interesting thing is, during each execution, the number of rows added varies.
Why is this happening? what is my mistake?
Any ideas and suggestions are welcome.
Make sure you are running the latest patches and updates for SharePoint.
Earlier versions in 2007 would allow cyclic self-triggers (e.g. re-triggering). Later versions do not (but still allow co-cyclic triggers). I suspect this is the problem and a "cascade" is starting by Update method. Just a hunch.
This should be fixed in SP2: Service Pack 2 prevents an on-change workflow from starting itself

why my sharepoint workflow always stop when i use this code?

I need to find an user in a list to set the assignedto task property, these informations are in a list. So i use this method :
public static SPUser GetSPUser(SPListItem item, string key){
SPFieldUser field = item.Fields[key] as SPFieldUser;
if (field != null)
{
SPFieldUserValue fieldValue = field.GetFieldValue(item[key].ToString()) as SPFieldUserValue;
if (fieldValue != null)
{
return fieldValue.User;
}
}
return null;
}
The problem is that when i use this method or this part of code, my workflow stop without saying anything. Here an exemple of code when i use it :
using (SPSite site = new SPSite(adress_of_my_site))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.Lists["Acteurs du projet"];
SPView view = cobj_ListeDesActeursDuProjet.DefaultView;
SPListItemCollection itemcollection = list.GetItems(view);
foreach (SPListItem item in itemcollection)
{
SPUser lobj_acteur = Utilities.GetSPUser(item,"acteur");
// Dictionary<string,class>
ActeursDuProjet[item["Rôle"].ToString()] =
new ActeursDuProjet()
{
Login = lobj_acteur.LoginName,
Email = lobj_acteur.Email
};
}
}
}
If i comment the content of my foreach my workflow continue as well...
If anybody have an idea it will be cool.
Regards,
Loïc
edit: problem in the code
Here are some debugging tips that might help:
ULS logs
Any exceptions should be reported here in some detail.
Enable debugging for all .NET code
This will cause the debugger to break whenever an exception occurs in SharePoint as well as your code. The downside is that the debugger will break on 'normal' exceptions that cause no side effects. So don't be misled!
To enable: Go to Debug, Exceptions and tick Common Language Runtime Exceptions. Also go to Tools, Options, Debugging and untick Enable Just My Code. Then attach to w3wp.exe.
Commenting code
You could also comment out all of your code. If the workflow step fails, you know there is a problem elsewhere. If the workflow step passes, then start uncommenting code until it fails - then you know where to look.
I tried commenting this above but it didn't format nicely so here it is.
It probably is fine, but this looks fishy to me:
// Dictionary<string,class>
ActeursDuProjet[item["Rôle"].ToString()] =
new ActeursDuProjet()
{
Login = lobj_acteur.LoginName,
Email = lobj_acteur.Email
};
I would think it would be something like:
// dictionary declared somewhere earlier
Dictionary<string,ActeursDuProjet> roles = new Dictionary<string,ActeursDuProjet>();
// inside the foreach
string role = item["Rôle"].ToString();
if (!roles.ContainsKey(role))
{
ActeursDuProjet foo = new ActeursDuProjet();
foo.Login = lobj_acteur.LoginName;
foo.Email = lobj_acteur.Email;
roles.Add(role, foo);
}

Resources