Webhook: "CURYID" Error while creating a new project from webhook

  • 11 May 2022
  • 4 replies

Userlevel 2

Hello Everyone,

We are trying to create a new project from webhook but it is giving “CURYID” cannot be empty error with below code. I have assigned curyid field in the code as well, but getting same exception.

 public class Testwebhookclass : PXGraph<Testwebhookclass>, IWebhookHandler
public async Task<System.Web.Http.IHttpActionResult> ProcessRequestAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
var resultresponse = new OkResult(request);

var projectGraph = PXGraph.CreateInstance<ProjectEntry>();
//Customer customer = PXSelect<Customer, Where<Customer.acctCD, Equal<Required<Customer.acctCD>>>>.Select(projectGraph, customerCD);

PMProject objNewProject = new PMProject();
objNewProject.ContractCD = "TestPJ1";
objNewProject = projectGraph.Project.Insert(objNewProject);
// objNewProject.CustomerID = customer.BAccountID;
//objNewProject = projectGraph.Project.Update(objNewProject);

PMProject Templatedetails = PXSelect<PMProject, Where<PMProject.contractCD, Equal<Required<PMProject.contractCD>>>>.Select(projectGraph, "INTERNAL");
objNewProject.TemplateID = Templatedetails?.ContractID;
//projectGraph.Project.Cache.SetValueExt<PMProject.templateID>(objNewProject, Templatedetails.ContractID);
//objNewProject.CuryID = "USD";
//objNewProject.DefaultBranchID = 16;
projectGraph.DefaultFromTemplate(objNewProject, Templatedetails.ContractID, new ProjectEntry.DefaultFromTemplateSettings()
CopyProperties = true,
CopyTasks = true,
//CopyBudget = false,
CopyAttributes = true,
//CopyRecurring = false,
//CopyEmployees = false,
//CopyEquipment = false,
CopyNotification = true,
CopyAccountMapping = true,
CopyCurrency = true
objNewProject.Description = "Test project name";
objNewProject = projectGraph.Project.Update(objNewProject);
return resultresponse;

The same code is working fine in the custom button without using webhook. Why it is not working through webhook?

Can anyone suggest the approach to create a project from webhook?





Best answer by Dmitrii Naumov 11 May 2022, 16:09

View original

4 replies

Userlevel 7
Badge +5

In order to have proper CuryID (and other fields) defaulting you need to work in scope of some branch. 

Try this code before the line that creates the graph:

Userlevel 7
Badge +5

I’m having the same problem.  Using this example from GitHub I have wrapped my code with:

using (var scope = GetAdminScope())


 Below is GetAdminScope:

private IDisposable GetAdminScope()
var userName = "admin";
if (PXDatabase.Companies.Length > 0)
var company = PXAccess.GetCompanyName();
if (string.IsNullOrEmpty(company))
company = PXDatabase.Companies[0];
userName = userName + "@" + company;
return new PXLoginScope(userName);

My PXDatabase.Companies.Length value is 0 which seems wrong.

I see that the scope variable has a Branch property that is null and scope.Company is also null.


PXLogin.SetBranchID(16); //pulled 16 from the Company table

after the call to GetAdminScope doesn’t affect my scope.Branch value.

Even forcing GetAdminScope to return:

return new PXLoginScope(userName + "@" + "Company")

doesn’t populate the scope variable Branch and Company

(“Company” is the CompanyCD for my company)

Userlevel 7
Badge +5

Note for future me: GetAdminScope only wanted to return “admin” in this case and not “admin@Company”.  When I debugged my code I looked at the AccessInfo cache and noticed that the ContactID, nor the UserID field values were filled in. I went back to GetAdminScope and removed the fix I thought I was making that helped to solve my issue.

Also, the webhook was returning PXOuterException but when I debugged the exception object I found clues within the InnerException which led me to the above.

Userlevel 7

Thank you for sharing this with the community @ddunn !


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved