Question

REST API not creating new record


Userlevel 2
Badge

Hi All. I am using Post Man to create new records using PUT REST API in Acumatica. I have created new screen (grid view) and new table attach with Screen. I am trying to add new record but its not creating record but updating the existing one I have tried with if-none-match header but still the problem exist. The table have PK and Unique key. Any idea what’s going on? Thanks

 


25 replies

Userlevel 7
Badge +5

Based on the screenshot, the primary key on your table is only on the CompanyID field and not the combination of CompanyID and, presumably, packing_id.  You’ll need to fix that in SQL or with DDL statements if you don’t have direct access to the SQL server.

That also means that your DAC is likely not using IsKey correctly. Can you share your DAC with us?

Userlevel 2
Badge

 

Userlevel 2
Badge

how can i create the combination? Packing Id is unique key in the table. So when ever we have new packing id it will create new record in Table.

Userlevel 7
Badge +5

What fields make up your primary key?  CompanyID and Packing_ID?  Is your Date field part of the primary key?

Also, you should avoid naming fields using reserved words, like “Date”.  You will also likely experience issues with fields that have underscores in their field names.

I’d recommend restarting the customization and renaming your fields to avoid problems as you get further into your project.

Userlevel 2
Badge

Company Id is my primary key and unqiue key is packing_id. Date field is not the part of any primary or unique. So you recommend me to remove underscores from fields name in screen or in the table?

Userlevel 7
Badge +5

Your primary key needs to be changed to CompanyID and packing_id. Then remove the unique key because that will cause problems if you create another tenant in that same database.

And, yes, I strongly recommend that you remove the underscores from the database field names.  Other programmers have found issues since the framework will use the underscore character when constructing queries and joins with other DACs.

Userlevel 2
Badge

Still the same problem its updating the existing one and not creating new one. Look at the table now and API. The screen shot is after when i changed it to 25698 before it was 4447
 

 

Userlevel 7
Badge +5

Share your new DAC - I suspect your issue will now be in there.

Side note, not important now, but the convention is to have CompanyID as your first column.

Userlevel 2
Badge

THis is new DAC.. 
 

 

Userlevel 2
Badge


@Django 
namespace RSL_Product
{
  [Serializable]
  [PXCacheName("AGDC_RSLProduct")]
  public class AGDC_RSLProduct : IBqlTable
  {
    #region PackingID
    [PXDBInt(IsKey = true)]
    [PXUIField(DisplayName = "Packing ID")]
    public virtual int? PackingID { get; set; }
    public abstract class packingID : PX.Data.BQL.BqlInt.Field<packingID> { }
    #endregion

    #region PackingDescription
    [PXDBString(255, InputMask = "")]
    [PXUIField(DisplayName = "Packing Description")]
    public virtual string PackingDescription { get; set; }
    public abstract class packingDescription : PX.Data.BQL.BqlString.Field<packingDescription> { }
    #endregion

    #region Date
    [PXDBDate()]
    [PXUIField(DisplayName = "Date")]
    public virtual DateTime? Date { get; set; }
    public abstract class date : PX.Data.BQL.BqlDateTime.Field<date> { }
    #endregion

    #region Swrc
    [PXDBString(255, InputMask = "")]
    [PXUIField(DisplayName = "Swrc")]
    public virtual string Swrc { get; set; }
    public abstract class swrc : PX.Data.BQL.BqlString.Field<swrc> { }
    #endregion

    #region CaseCode
    [PXDBInt()]
    [PXUIField(DisplayName = "Case Code")]
    public virtual int? CaseCode { get; set; }
    public abstract class caseCode : PX.Data.BQL.BqlInt.Field<caseCode> { }
    #endregion

    #region CaseUpc
    [PXDBString(255, InputMask = "")]
    [PXUIField(DisplayName = "Case Upc")]
    public virtual string CaseUpc { get; set; }
    public abstract class caseUpc : PX.Data.BQL.BqlString.Field<caseUpc> { }
    #endregion
  }
}

Userlevel 7
Badge +5

That’s looking correct. Sometimes I need to do an application restart to get things actually working.

Something else to check - the graph that your web endpoint is connected to - does it work with adding multiple records?

Userlevel 2
Badge

You mean endpoints? Check screen shot below

@Django 

 

Userlevel 7
Badge +5

Your endpoint is connected to screen MA.20.88.61. Are you able to use that screen to enter multiple records into that table?

Userlevel 2
Badge

Nope it’s saving the records from screen too

Userlevel 7
Badge +5

Sorry - just to be clear, is that screen functioning properly?  Can you add / edit more than one record in that screen? 

The reason I ask is that the Endpoint is going to use that Graph for it’s business logic and if the screen isn’t working properly, then that will impact your Endpoint.

Userlevel 2
Badge

@Django It’s not saving from screen either
 

 

Userlevel 7
Badge +5

First thing to check is run a Restart Application (screen SM203510) and see that clears things up.

If it isn’t still working then it might be easier to re-create the screen, make sure that’s working, and then delete and re-create your endpoint. You need the screen to be working since your endpoint connects to the screen.

Userlevel 2
Badge

Do i need to create save or create action on screen ? I have created a simple screen with grid view only nothing else no entry forms or anything. Does this creating problem? 

Userlevel 7
Badge +5

Based on your screenshot I see the + button and the 💾 button so those will do everything the form needs to do to tell the graph to persist the data to the database.

You don’t need to add anything else.

But if that screen isn’t working, then the endpoint won’t work either.

Userlevel 2
Badge

@Django Yes there is button but when i am saving the data and click on it its not working when i reload the page it shows popup

Userlevel 7
Badge +5

If you share with us the popup, we might be able to see what’s wrong with the screen.

Alternatively, it might be easier just to delete and re-create the screen since it’s a fairly basic form.

Userlevel 2
Badge

@Django  the second record with packing id 5587 is not saving even i clicked on it and when i reload it shows me this

 

Userlevel 7
Badge +5

It’s hard to tell if the issue is in the screen setup or in the graph. Can you package up your customization project and post it?

Userlevel 2
Badge

@Django here is my package. Please have a look and please guide me what I am missing. I have spent alot of time on it

Userlevel 2
Badge

@Django did you get the time to check?

 

Reply


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