Grails - How to modify list items from g:select dynamically - ajax

I have a domain class called Client with typical attributes (name, surname, and so on).
There's also a class called PaymentConditions (which establishes some parameters to calculate the amount that a client has to pay) which have a reference to Client. A Client can have many PaymentConditions.
And finally there's a Payment class with attributes like paymentDate, amount and a reference to Client and PaymentConditions.
When I want to register a Payment I use an Ajax call to retrieve data from the Client (including the client id) that is making the payment. But the problem is that because of the reference to PaymentConditions there's a drop-down list with all the payment conditions registered. What I need is to filter the drop-down list items to show only the ones that are related to the retrieved client.
Can you help me with this?
Thanks in advance!
EDITED: There's an input field in the form where the user has to enter the Client's surname. This input field has implemented the JQuery UI autocomplete feature, so when a Client is selected the PaymentConditions drop-down list must be updated or filtered for the retrieved Client.

For showing dropdown list grails provides a special select tag-
<g:select name="paymentCondition" //Name you want to send back to server
from="${client.paymentConditions}" //Client wise filtered conditions where client is a passed client instance
value="${client.paymentConditions.id}" //Selected option value to send to server
/>
Or if you want to filter the list out in controller only then you can do-
def client = Client.get(id);
def paymentConditions = client.paymentConditions
Use the way you like according to your implementation. Hope it helps.

Related

note passed in as part of CreateCheckoutRequest, but where to on the payment page or the dashboard to view them?

I am using nodeJs, and I have passed in note inside CreateCheckoutRequest, however, i am not seeing the note showing on the payment page url generated by createCheckout or the dashboard page.
My ultimate goal is our frontend can pass in the phone number as note to sqaure-connect, so that we can view the phonenumber from our dashboard once the customer completes an order
Tried to look at old transactions, since we didnt use note, didnt see any note.
const checkout = SquareConnect.CreateCheckoutRequest.constructFromObject({
idempotency_key: 'sample_key,
order: orderRequest,
redirect_url: redirect_url,
ask_for_shipping_address: true
note, // need to see it from dashboard once the user completes an order
});
When adding a note to a CreateCheckout request, it will end up on the tenders->note field of the associated transaction. To clarify, once the customer has paid on the checkout page, it should redirect to your web page (based on your redirect_url field that you passed to CreateCheckout originally). From there, the url will contain a parameter called transaction_id. You can then use this id to retrieve the transaction and digging into it to find the note (transaction->tenders[0]->note). In this particular use case, there will always only be one tender since Checkout doesn't allow multiple tenders.
Now, to actually answer your question: the tender note will be displayed as the main text you see when you view your transactions. So when you login to your Square Dashboard and click Transactions, in the main list, the "header" will be whatever the tender note was.

How to get a user selection value in Watson Conversation

I am trying that the user selects an option from a <select> responded by Watson and store the value selected in a variable.
I have done that the Watson Conversation's response show a list of values to select (using HTML), but we don't get to store the value selected in a variable.
Is that possible?
Watson conversation is stateless. In order to capture user interaction/feedback, you need your UI/application layer to handle it.
You could create custom id/class tags in your select which the UI intercepts and knows how to respond to conversation.
It's possible but, you have to be careful. So, this because the Conversation control the information in a session named context, and this is trafficked for application in all request/response (yeah, you need send for the API the conversation id in the interactions of the dialog).
In node for Dialog, you click in response/advanced and insert this:
"context" :
{
"your_property": "values"
}

Restful URL After Insert

I am new to RESTful URLs and I have a general question. Let's say I have a URL that I use to retrieve student records: somesite.com/students/123 which retrieves the details for the student with ID 123.
I then do the following to load an empty form for adding students: somesite.com/students/0 where zero indicates that I want to display an empty student detail form (or somesite.com/students/new).
The question I have is that after I add a student record I get back a new Id. However, if I add the record using AJAX without submitting and refreshing the page, my URL still shows somesite.com/students/0. If a user clicks refresh then the empty form is displayed again rather than the new student record.
How should that be handled?
It's not like your server can't respond to AJAX requests, right?
All you need to do is send back the newly generated ID, and then:
Use window.location = 'new_url' to redirect the user
Or even better, use history.pushState() (if available) to change the URL without any redirection (and reloading) happening at all
One thing that seems off, though, is the use of GET page/students/0 to get an "empty record", or, as I understand it, a "template" for new records. I don't think that's how RESTful services work, but then again, I'm not an expert in REST services.

How to return output to client side (rest call) from Microsoft.Xrm.Sdk.IPlugin?

I have created a custom entity and a matching plugin.
The plug-in registers on the Create message of the entity, pre-operation, and synchronous.
Via a rest call the plugin execution is triggered. The input is correct. But I can not get the data out to the client side.
Should I set OutputParameters, change the InputParameter, change plugin registration, ...?
Or should I retrieve the entity afterwards?
This pattern is described at
http://crm.davidyack.com/journal/2012/6/26/crm-client-extension-data-access-strategies.html under the command pattern segment
To update some values in record in Pre-Create you can use something like this:
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity yourEntityName= (Entity)context.InputParameters["Target"]
if(yourEntityName.Attributes.Contains("SomeAttribute"))
yourEntityName.Attributes["SomeAttribute"] = "SomeValues"
}
Is that what you are looking for?
Change "SomeAttribute" for attribute name that you want to change and "SomeValues" for value that you want to pass into record.
On PreCreate event populate Text area with your results. At the end of Create, your entity will have this field populated with results. In rest call retrieve the entity after it is created and retrieve the results from Text area.
If you are using CRM 2013, instead of using custom entity and Plugin, you can use Actions to carry out server side execution and Actions can be called from REST calls. Actions is like any SDK Message where you can provide inputs and it will have Output.
hth
Thanks
Mak

Creating dynamic web forms on the client side

Is there an existing library that would do this?
I want to be able to have code on the client side where the user chooses something, it makes a call to the server, and the server sends back "for this option, you need a have a text field called foo and a select field called bar with the following options, this one is selected, etc", and then the client side builds the next part of the form from that information. Or if they choose a different option, a different set of fields and values is returned from the server and populated on the screen. Also it might cascade so after the first selection we need a select field with some options, and then depending what they select on that select field the next field might be another select field or it might be a text input field.
Has anybody done anything like that? Is my best choice to have the AJAX call return some html that I just stuff into a div, or can I do it field by field and value by value?
If it matters, the back end is going to be written in Perl/MASON, and the front end will be using Javascript/JQuery/JQuery-UI.
I would use jquery and submit AJAX calls to whatever backend system you choose. Have this backend system compute the necessary changes and return the info as JSON. Let JQuery parse it for you and append the necessary form elements. However, it seems like under alot of use cases these decisions could be made on the client side without even talking to the server just as we pre validate form input before allowing posting to the server. I don't, however, have your requirements in front of me so I am sure there is a reason you want to get the info back from the server.
P.S. please do not return pure html from the back end to the client....ever.

Resources