Skip to main content

we have a requirement to update few fields in stock Items screen, but we are facing “Field not found: 'PX.Objects.IN.InventoryItemMaintBase.Item'." error. Please have a look at below code.
we are on Build 22.109.0023.

 

using Newtonsoft.Json;
using PX.Data;
using PX.Data.Webhooks;
using PX.Objects.IN;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Results;

namespace WebHooksConfiguration
{
    public class ObjectInventoryItemJSON
    {
        public string InventoryId { get; set; }
        public string Description { get; set; }     
    }
    public class KWInsInventoryItemSync : IWebhookHandler
    {
        public async Task<System.Web.Http.IHttpActionResult> ProcessRequestAsync(
       HttpRequestMessage request, CancellationToken cancellationToken)
        {
            using (var scope = GetAdminScope())
            {
                if (request.Method == HttpMethod.Post)
                {
                    string jsonContent = request.Content.ReadAsStringAsync().Result;

                    var obj = JsonConvert.DeserializeObject<ObjectInventoryItemJSON>(jsonContent);

                    if (obj != null)
                    {
                        using (var ts = new PXTransactionScope())
                        {
                            ProcessData(obj.InventoryId, obj.Description);

                            ts.Complete();
                        }
                    }
                }
            }

            return new OkResult(request);
        }

        public void ProcessData(string InventoryId, string Description) 
        {
            if (!string.IsNullOrEmpty(InventoryId))
            {
                var graph = PXGraph.CreateInstance<NonStockItemMaint>();
                InventoryItem newItem = graph.Item.Search<InventoryItem.inventoryCD>(InventoryId);

                if (newItem != null)
                {
                    graph.Item.Current = newItem;
                }
            }
        }      
        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);
        }
    }
}
 

Hi, @ckwiat46  I just modified a little bit of your code, can you please try the below code?

using Newtonsoft.Json;
using PX.Data;
using PX.Data.Webhooks;
using PX.Objects.IN;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Results;

namespace WebHooksConfiguration
{
public class ObjectInventoryItemJSON
{
public string InventoryId { get; set; }
public string Description { get; set; }
}
public class KWInsInventoryItemSync : IWebhookHandler
{
public async Task<System.Web.Http.IHttpActionResult> ProcessRequestAsync(
HttpRequestMessage request, CancellationToken cancellationToken)
{
using (var scope = GetAdminScope())
{
if (request.Method == HttpMethod.Post)
{
string jsonContent = request.Content.ReadAsStringAsync().Result;

var obj = JsonConvert.DeserializeObject<ObjectInventoryItemJSON>(jsonContent);

if (obj != null)
{
using (var ts = new PXTransactionScope())
{
ProcessData(obj.InventoryId, obj.Description);

ts.Complete();
}
}
}
}

return new OkResult(request);
}

public void ProcessData(string InventoryId, string Description)
{
if (!string.IsNullOrEmpty(InventoryId))
{
var graph = PXGraph.CreateInstance<NonStockItemMaint>();
InventoryItem newItem = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(Base,inventoryid.Trim());


if (newItem != null)
{
graph.Item.Current = newItem;
}
}
}
private IDisposable GetAdminScope()
{
var userName = "admin";
if (PXDatabase.Companies.Length > 0)
{
var company = PXAccess.GetCompanyName();
if (string.IsNullOrEmpty(company))
{
company = PXDatabase.Companiese0];
}
userName = userName + "@" + company;
}
return new PXLoginScope(userName);
}
}
}

 

 

 


Hello @Naveen Boga i tried the code you suggested but still facing same issue.

//at this place we are getting error.
graph.Item.Current = newItem;


Hi @ckwiat46 were you able to find a solution? Thank you!


Reply