How do I send a custom error message to the client a Telerik MVC Grid Ajax Insert/Update/Delete? - telerik-grid

I am working with Ajax Editing within a Telerik Grid extension. I would like to handle errors/exceptions on Insert/Update/Delete and display a user friendly message in the message box that is displayed back to the client, instead of the default message of "Error! The requested URL returned 500 - Internal Server Error" or the like.
Is there a way to tell the grid to display a custom text message?

Someone customized the alert here: http://www.telerik.com/community/forums/aspnet-mvc/grid/how-to-return-error-information-to-grid-in-ajax-editing-mode.aspx, but I'm still searching for a way to actually update the grid itself...
There's a little hope in the client-side grid's noRecordsTemplate property, but we still need a way to clear the grid of any records that may have already been there.
Edit:
Found it: To clear the grid, and set your message, do the following:
var grid = $('#Grid').data('tGrid');
grid.total = 0;
grid.dataBind(Array());
$('#Grid').find('.t-no-data td').text('My Custom Error Message');
Of course, you can figure out on your own how to combine the my example and the example from the link above.

Related

How To Know When A CS Cart Hook Fires?

I need to confirm if I have selected the right hook from the hooks database. I need to auto order a vehicle on confirming an order. I chose the change_order_status and registered it in my init.php using
fn_register_hooks(
'change_order_status'
);
now in my func.php I have
if (!defined('AREA')) {die('Access denied');}
function fn_dellyman_change_order_status(&$status_to,&$status_from,&$order_info,&$force_notification,&$order_statuses,&$place_order) {
//Getting authentication data to identify user
$auth = $_SESSION['auth'];
var_dump($auth);
}
when I go to orders and switch the order from say open to complete, I expect to see the contents of auth rendered to the page at least as part of the request response. However I see no indication that the hook selected is the right one. How can i ensure the hook called is correct.
depending on your CS-Cart version since 4.6.x is Tygh::$app['session']['auth'] but also depend if is done by AJAX request or normal place/edit order
On AJAX request you will not get any notification.
please try to use for a nicer notification:
fn_print_r(Tygh::$app['session']['auth']);
Use
fn_set_notification('W','Description', var_export($varialble,true) );
this gives a notificcation after the hook fires and I found it very useful for my dev purposes.
The W can also be I and E for information and Error. Basically all it does is change the style of the popup

Alert in view record for Netsuite

I have been trying to get a alert in Netsuite for view mode but can't get it for customer record.
Though when I tried to get the alert for the edit record then I got it but I want it for view.
I tried client script, user event script and also workflow. But all support only for edit. Can I get the alert by any means for the view record option.
Thanks
Gladiator
One workaround that I've done is to add a custom field of type 'Inline HTML' to the customer form. Then during the beforeLoad event you can check if type == 'view' and update the custom field's value with the HTML that is needed to display the alert.
Basically form.setScript used to work with SS1 but there was no (not hacked) API access to Netsuite's alerts
SS2.0 gives nice access to the alert system but it doesn't load in view mode unless you take a supported action (clicking a button)
See this answer for a sample with SS2 that loads your script and shows an integrated alert.
SS2.0 Display Message on Record
Thanks Mike, Michoel and Bknights.
Here is the solution to the problem.
Create an inline html field on the customer form.
Since the field does not store value nlapiSetFieldValue for before load function works absolutely fine.
Below is the snippet of the working code.
function before_load(type)
{
if (type == 'view')
{
var pass_value = "<html><body><script type='text/javascript'>window.alert('Hello World!!!')</script></body></html>";
nlapiSetFieldValue("custentity25", pass_value); //custentity25 is the id of Inline HTML field we created
}
}
Note : The "" used should be different then the one used in the HTML code which is ''. If same are used then there will be an error.
You need to use a User Event Script, and in the before load event, set a Client Script via form.setScript(). In your "injected" Client Script, you can display the alert.

XPages: possible bug with enableModifiedFlag in Release 9.0.1FP3 HF241, and workaround

I have a page where I wanted to use the "enableModifiedFlag" property, to let users know that their edit was not saved if they want to leave a page before saving.
I also have a search box in that page, and when I set the field to the static value "true", the message was popping because the search box was considered part of the page, and the field was modified. This all makes sense.
Since the "enableModifiedFlag" property can be computed, I decieded to set it to true only if the document was in edit mode, as the search box is not available at that time. The behaviour I got was that the message was not appearing anymore. I then tested with returning true as the value of the property, and it didn't change anything: the message was just gone. I then used the static values and set it to true, and the message was then appearing.
My conclusion is that there is a bug that prevents any computed value to be considered for that property.
So I had to find a workaround to prevent the message from popping up when users used the serach box. Here is the solution I came up with.
On the client side, we have access to the XSP object. One of its method is XSP._setDirty(). you can either set it to true or false, and it will affect if the page diplays the popup message or not. So in my search button, I added this code on the onclick event, on the client side:
XSP._setDirty(false,""); //so we don't get the "do you want to leave this page" message
showStandBy(); //show standby in case search is long or slow
return true;
That way, I tell my page not to show the message and the popup is not displayed.
It's still a shame you can't use the computed value for that property, but at least we have a workaround. Hope this will be useful to somebody!!!
GOT SOMETHING WORKING I THINK
This is what I have now, that controls teh flag:
<xp:this.enableModifiedFlag><![CDATA[${javascript:context.getUrlParameter("action")=="editDocument";}]]></xp:this.enableModifiedFlag>
I would rather use the document1.isEditable() function, but I wasn't successful with it so far, neither computed dynamically nor on page load.
At leaset I have something that seems to be working. Time to submit that code to the end users!

Determine Selected Item and Current Page of Telerik MVC Grid - Client Side

I am using the Telerik MVC grid, with Ajax data binding.
I would like to do 2 things with the Telerik MVC Grid:
When a row is selected, detect (client side) which page the grid is currently on as well as which row was selected.
The next time the grid is loaded (using ajax ... I never leave the page), page back to the same page to show the last select. (I guess I am really just asking if there is a way to immediately go to a page of the grid once the data is loaded, rather than page 1)
Please keep in mind, I am aware of the client side events already. I would like to know how to do #1 from the event, and #2 either from the client side or programatically somehow.
Edit/More Details: I think I know what I need to do here. Since I am using Ajax loading here, the Ajax POST is being called somewhere in the Telerik code. I can see that during that Ajax POST they are sending a "page" parameter to the controller. If I could edit that somehow, I am sure it would work - but I am having trouble changing that parameter.
Thanks in advance!
For the sake of anyone else looking for this, I figured it out:
Getting the current page of the Grid:
To do this, I use jQuery to determine which number has the "selected" style (t-state-active) to determine the current page number. Example (my grid id is 'cases-grid'):
function getCurrentGridPage() {
///<summary>Gets the current page of the #cases-grid</summary>
var page = $('#cases-grid .t-state-active');
if (page.length == 0) {
return 1; //default to page 1 when unknown
}
return page.text();
}
The second part of my question was actually well documented on the Telerik site ... I just missed it for awhile. To load the grid to a specific page (other than 1) I added the following to my grid:
.Pageable(pager => pager.PageTo(#Model.InitialPage))
And added the InitialPage property to my model.

How to add link to error message within ItemDeleting event receiver method?

I have an SPList event receiver method like:
ItemDeleting(ByVal voHttpContex As HttpContext, ByVal voProperties As Microsoft.SharePoint.SPItemEventProperties)
To block unwanted operation i uset this code:
voProperties.Cancel = True
voProperties.ErrorMessage="This is my error message."
After executing above code error message within error page is shown.
Is there a way to add to this error message html link to another page?
I was tying to use "a" html tag but it was displayed explicitly on page and wasn't recognized as a Html code to be transformed and parsed.
Do anybody knows how to add this link to the message? Link should have of course some name like "click here" instead of "http://blablabla.bla" format.
Unlikely by using ErrorMessage - whatever code in SharePoint is outputing this message is useing HTMLEncode and you're not going to be able to stop that.
With SP2010 .Cancel is depreciated and you could use Status = CancelWithRedirectUrl
voProperties.Status = CancelWithRedirectUrl;
// Redirect to some page that shows your error and provides link.
voProperties.RedirectUrl = "someurl.htm";

Resources