Connector Custom Invalid Action Message

Hi all.
I use the connector.
I have an custom update
function …
db_query
if … etc etc …

$action->invalid(); $scheduler->event->attach("beforeProcessing", "custom_update");

on the client side I have:

dp.defineAction("invalid", function(xml){ alert("Error Bla bla bla"); return true; });

Can I provide to client side an custom alert message based on different invalid action situation ?

Thank you.

Sondra

Hello,

You can set custom attribute which will be added to the related action tag in XML response using set_response_attribute method.
Check out additional information on the data action object page.

Best regards,
Ilya

Hi,
Can you provide an example?
I don’t understand the concept.

thank you.

Sondra

Hello,

dp.defineAction("invalid", function(xml){ alert("Error Bla bla bla"); return true; });
Here you are receiving reply from the server for the particular event in the xml form. If serialized it looks like this:

"<action type="invalid" sid="71" tid="71"></action>" 

With the help of set_response_attribute method we can add attributes to the xml so later you can build custom logic around them.

For example,
PHP:

[code]$scheduler->event->attach(“beforeUpdate”,myUpdate);

function myUpdate($action){
$action->invalid();
if($action->get_value(“event_name”)=="") {
$action->set_response_attribute(‘ErrorMessage’,‘Event is missing name.’);
}
else {
$action->set_response_attribute(‘ErrorMessage’,‘Event is not missing name yet is still somehow incorrect.’);
}
}[/code]

JS:

dp.defineAction("invalid", function(xml){ if(xml.attributes.ErrorMessage) alert(xml.attributes.ErrorMessage.value); else alert('Generic error occured'); return true; });

Now error message set in the xml’s ErrorMessage attribute will be displayed or a generic one if the attribute is missing.

Hope this helps.

Best regards,
Ilya