How to handle required fields in Shopware 6 administration? - shopware

I'm trying to add validation in custom form in administration.
The required field has required property.
I've also added required flag in entity definition (with ->addFlags(new Required())), and when I save form with empty field, I've got an error from endpoint that says the field is required.
But I can't figure out how to show error message under this field.
For example when I'm creating new sales channel and save empty form, there are error messages under required fields.
How can I add this kind of error handling?

I think I've found it.
There is mapApiErrors function which maps api errors from global state to given entity and properties.

Related

How to get 'Bills and Adjustment' grid fields in an endpoint extension

I'm working with a client on obtaining Bills and Adjustments values through the Contract based web services. I understand that certain fields aren't available in the Default Endpoint, and have to be obtained through an extension.
I'm trying to add fields from the Bills and Adjustments' Applications tab, but I'm running into a warning that I don't understand. If I extend the Default endpoint for 'Bills' (call it 'BillExt'), and I try to add the Reference Number field from the 'Applications' tab/grid (or any other field from that grid) - I get the following warning (see screenshot below)...
Can someone explain what the issue is, and how I go about adding these fields from the 'Applictaions' tab/grid? I've added fields from the 'Approval Details' grid without this warning without a problem. Is this a warning I can disregard?
You are trying to add a field from another table/view that can return multiple rows for a single Bill.
The correct way to do this is by adding a separate collection on the object and map the view on that collection. e.g: Applications or Details collections here.
That collection will have the information for all records related to the header once you retrieve them using the ?$expand=Details on the query string request.

Acumatica API PO insert errors

I've been having many problems inserting a Purchase Order using the API because it often responds with errors which are vague or don't identify the cause correctly. We have quite a few customizations for the site involved, so to narrow down the issue, I created a new clean Acumatica ERP installation (v17.210.0034) to work with, with no endpoint extensions, and installed the SalesDemo data in both.
Even with clean installation sites like this, I'm still getting vague errors when trying to insert a PO. For example, I followed the steps below, using Postman to call the API:
Login: POST to url = "http://localhost/Acu172100034/entity/auth/login, with JSON credentials in the body. Response = success.
GET a PO: url = http://localhost/Acu172100034/entity/Default/17.200.001/PurchaseOrder/RO/PO000696?$expand=Details,ShippingInstructions. Response = JSON data for the PO
I copied the JSON in the GET response above and pasted it into a new PUT request body. I removed all "id", "rowNumber", "custom" and "files" fields. I removed the "OrderNbr" field in the header and detail rows since it is an auto-number field for a PO.
I attempt to insert a new PO using the modified JSON with a PUT: url = http://localhost/Acu172100034/entity/Default/17.200.001/PurchaseOrder,
The error response includes: "PX.Data.PXException: Error: 'Branch' cannot be empty.\r\nError: 'Ship To' cannot be empty.\r\nError: 'Location' cannot be found in the system.\r\n ---> PX.Data.PXOuterException: Error: Inserting 'Purchase Order' record raised at least one error. Please review the errors."
There is a BranchID specified on the PO Line, there is a Location specified on the PO header, and there is a ShipTo specified on the ShippingInstructions. The Location does exist. This error is obviously vague and misleading. Only by trial and error did I determine that I needed to change Hold from true to false to get past this error. I assume this is because there's some validation or rule which disallows an insert or update while on hold? After changing Hold to false and attempting an insert with a PUT again, I then get an error: "PX.Data.PXException: Error: An error occurred during processing of the field InventoryID: Object reference not set to an instance of an object.. ---> System.NullReferenceException: Object reference not set to an instance of an object." and the call stack includes POOrderEntry.POLine_ExpenseAcctID_FieldDefaulting and POOrderEntry.POLine_LineType_FieldUpdated event handlers.
There is an InventoryID on the PO Line, and the inventory item exists, so it looks like these event handlers are throwing errors for some reason when LineType is being set, but I'm guessing. Any ideas how to get this simple API insert to work?
Update (2/23/19): I modified the JSON for insert a bit more by changing the detail item Completed to "false", and the PO header Hold to "true", and the Status to "On Hold". The error mentioned above now changes to "Error: 'UOM' cannot be empty.\r\nError: 'Account' cannot be empty.\r\nError: 'Sub.' cannot be empty.". The UOM is not empty, Account is empty, and SubAccount is empty; but Account and SubAccount are not required fields for a PO Line.
After more trial and error, I was able to insert a PO by additionally changing the JSON being inserted by removing the two fields "QtyOnReceipts" and "ReceivedAmount". Can you see why the errors I'm receiving in the response in no way helps to find the cause of the error? I still don't even know why removing these fields resolved the error. The most reliable way to perform an API insert is probably -- as KRichardson suggested -- always insert first with only the minimum required fields, then perform an update with the rest. Or, perform a LOT of testing with trial and error to determine what fields and values allow for a successful insert. If I were to change or add field values in the JSON, or use JSON from a different record, I have no real confidence that the changes I made to get it to work will always work.

Marking a Form Element as Required Inside an EventSubscriber in symfony2

I have an entity with a member called 'mediaType', which tells me which of two other members to pull data from. When I'm building the form to create the entity, I have mediaType as a drop down and then two text fields for the other two members. What I want to do is force one or the other two fields to be required based on the mediaType selected (or neither, if the user select None. I'll handle hiding the fields with JS).
Since I'm manipulating the form after binding, I set up an EventSubscriber to listen on the PostBind event. My subscriber fires just fine, but I'm at a loss to figure out how to mark one of the fields as required. I can get the field, and I can check to see if it is required, but I just don't know how to make it required.
Is there a way to do this? Or is there a better way than using EventSubscriber?
You could use validations groups http://symfony.com/doc/current/book/forms.html#book-forms-validation-groups see "Groups based on Submitted Data"

CRM 2011 javascript onchange event not working for system field in another organisation

I have some javascript code attached to the accounts entity. This code sets the requirement level of the primary contact attribute based on the value of a custom option set field showing various account types. This was developed on one server, where it worked, and so the solution was imported into another organisation where it now doesnt work.
It seems to be only on this field as i have changed the code to look at another field and that works fine. The error it gives is that the "Object doesn't support this property or method". Also what is strange is that the field doesn't appear in the list under the entity within the solution despite it being a system field.
The code i'm using is:
Xrm.Page.getAttribute("primarycontactid").setRequiredLevel("required");
Can anyone help me figure out what it's doing?
Thanks
EDIT: Found that the code is actually making the field required despite the error, but it's not displaying the * next to it. Also if I make the field required in it's settings then it does the same thing

sharepoint validate custom field

I cave created a custom list in sharepoint (created and provisioned to the 12 hive)
how can i perform validation on certain fields of the list when a new list item is added?
i think i can do it through the "itemadding" event reciever, but is there a more elegant sharepoint way?
eg i just want to check an email field has a valid email format.
I think you have to options. As you have already mentioned using a event receiver would be one way. But I think a more elegant and above all a more SharePoint like way would be implementing your own custom field type and field control.
This will give you the option to validate the mail address before any event receiver is triggered and to react with an validation message to the user giving him the option to correct his input.
You could go with validation on the client using JQuery if you have the id or a css class on the rendered textbox for the email input.

Resources