Join our DNN Community    (Newsletter, Tips, Tricks and Forums for DNN Skins & Modules)

 


 
Microsoft Gold Certified Partner - DNN Benefactor

DotNetNuke Powered! 


Monday, December 01, 2008 Register · Login · Contact · Search:  
Company Solutions Portfolio Contact
Forums
General
The ever-powerful ListX module forum. Post your questions, new configuration ideas and reviews.
Subject: Testing for successful insert

You are not authorized to post a reply.   
Author Messages
pauldes
Immortal
Posts:1392

12/31/2006 8:50 AM Alert 
What I am trying to do is set an action variable that I set and display to the user after an execute action, based on the success or failure of an insert.

Say I have and action:execute called INSERT. After I do the actual insert, I am executing:
select scope_identity() as retval

This will return me the new recordid I just inserted and if the new record id is say, 51, [retval,INSERT] = 51

Then what I am trying to do is IF [retval,INSERT] > 0
SET [message,Action] = 'Record Added'
ELSE
SET [message,Action] = 'Insert Failed'

The problem is that if the insert fails my if statement LITERALLY tests the string "[retval,INSERT]" and it always tests as being > 0, so even when the insert fails, it displays a success message to the user.

How could I accomplish the task of testing if an insert succeeded or not to display that to the user?


ListX....makes you look brilliant, even though you're not.
nxtrack
Middleweight
Posts:53

12/31/2006 6:50 PM Alert 
I'm able to get a false on my failures. Are you wrapping your parameters in single quotes like this?
If '[retval,INSERT]' > '0'
pauldes
Immortal
Posts:1392

12/31/2006 9:58 PM Alert 
Nope, it doesn't seem to work for me. Here is my query and subsequent test of the execute:

Executing Query: INSERT INTO [DB].[dbo].[Rate_Group]
([Firm_Id]
,[Product_Id]
,[Currency_Id]
,[Code]
,[Rate_Type]
,[Rate]
,[Description]
,create_date, edit_date
,[Edit_UserId],[Create_UserId]
,[PortalId],[Level_Id],[status])
VALUES
([vMyFirmId,S]
,[sltProduct,F]
,[vDefCurrId,S]
,'@afldcode'
,'@afldtype'
,@afldrate
,'@aflddescription'
, getdate(), getdate()
,[*userid],[*userid]
,[*portalid],[LevelId],'@afldstatus')

select scope_identity() as retval

No table resulted from this execution.

If '[retval,INSERT]' > '0'
'[retval,INSERT]' > '0' = False
Failed: Skipping child actions.

ListX....makes you look brilliant, even though you're not.
pauldes
Immortal
Posts:1392

12/31/2006 10:01 PM Alert 
WAIT!! Never mind. Had it backwards after I added the single quotes. Thanks for the help!

ListX....makes you look brilliant, even though you're not.
empulse
Middleweight
Posts:81

08/18/2008 10:12 AM Alert 
Could like someone to elaborate a bit.
How do you handle user notification?

pauldes
Immortal
Posts:1392

08/18/2008 10:37 AM Alert 
You picked a OLD post..... :-)

Here's the 2008 version of evaluating success/failure.

Actions.....
IF '[DoUpdate,Q]'<>''
->Action:Execute[myUpdate]: Update TableA....... where recordid = [DoUpdate,Q]
->If '[myUpdate.isSuccessful,Action]' = 'True'
->->Assign Action Variable [aMessage] to 'Record Created'
->ELSE
->->Assign Action Variable [aMessage] to 'Your Update Failed
[myUpdate.Error,Action]

Then put [aMessage,Action] at the top of your Detail List html sections

ListX....makes you look brilliant, even though you're not.
empulse
Middleweight
Posts:81

08/18/2008 1:23 PM Alert 
Thanks for the response, I always do as much research as i can before posting question.

Unfortunately, I am still having trouble with the whole validation process.

A few question about the '2008 Version' (which still is not working for me.

I am doing this : HTML
<A class=CommandButton {ACTION,"Add","TransactionLog",,Message}> Save </A>

Then in Actions:

Message: Awaiting incoming message with Type 'TransactionLog' and Value 'Add'
->Execute [Insert] INSERT INTO .....
-> If '[Insert.isSuccessful,Action]' = 'True'
->-> Assignment: Assign <Action> variable '[aMessage]' to 'Record Created'.
-> Else
->-> Assignment: Assign <Action> variable '[aMessage]' to 'Record Not Added [Insert.Error,Action]'

At the top of the HTML I put [Message,Action]

There seems to be two problems here:
The "IF" structure after the Insert is not executing (at least there is no trace of it in Debug) and [Message,Action] is not getting assigned a value.

I also do not understand the logic behind the [Insert.error,Action] token.
I am also unclear as to what the indent level should be for the IF/ELSE structure.

BTW, The INSERT and d UPDATE statements are working fine.




pauldes
Immortal
Posts:1392

08/18/2008 1:42 PM Alert 
First, at the top of the html, you need to put [aMessage,Action] because you are assigned the Execute result message to an action variable called aMessage.

The IF that is testing the Execute result need to be at the same level of indentation as the execute.

The Insert.error,Action holds the Execute action's SQL response error message so that you can see what the error migh be and display it

Basically, every time you do an Execute SQL action, the [actionname.isSuccessful,Action] gets created and set to True if the query completes and the [actionname.Error,Action] gets created if the query fails and gets populated with the SQL server error response.

ListX....makes you look brilliant, even though you're not.
empulse
Middleweight
Posts:81

08/19/2008 12:20 PM Alert 
-

Strange things happening here:
The IF structure seems to be executing BEFORE the INSERT statement (At least that is the way it is listed in debug view) although in ACTIONS the INSERT comes first.

- also -

If the ELSE is on the same indent level as the IF, the ELSE always executes, regardless of what happens with the IF. If I indent the ELSE one step (same level as the assignment statement below the IF, the ELSE never executes)
pauldes
Immortal
Posts:1392

08/19/2008 5:11 PM Alert 
Not really sure what you would be referring to... post your debug.

ListX....makes you look brilliant, even though you're not.
empulse
Middleweight
Posts:81

08/20/2008 5:31 PM Alert 
Part at a time - debug from a successful insert - it looks like the insert is occurring after the statement to assign a value to aMessage, so there is no result to assign to the Action variable :

* Execute Query[qryGetAbbr]: USE ......
o Skipping (indentation beyond parent scope).

# Assignment: Assign <Action> variable 'aMessage' to 'Test aMessage Variable'.
* Skipping (indentation beyond parent scope).

* Message: Awaiting incoming message with Type 'TransactionLog' and Value 'Save'.
o Parsing Action
o Skip

* Message: Awaiting incoming message with Type 'TransactionLog' and Value 'Add'.
o Parsing Action
o Passed: Handling actions for 'TransactionLog' with a value of 'Add'
o Executing
# If = 'True'
* = 'True' = False
* Failed: Skipping child actions.
# Execute Query[qryInsert]: INSERT INTO .....
* Executing
* Executing Query: INSERT INTO ........
pauldes
Immortal
Posts:1392

08/20/2008 6:28 PM Alert 
Something's really messed up. I'm pretty sure it's your syntax in your actions but can't tell. Export your module to an XML file and attach to a post....<hint> use the Add Reply link to get to the attachment upload form, not the Quick Reply.

ListX....makes you look brilliant, even though you're not.
empulse
Middleweight
Posts:81

08/21/2008 12:38 PM Alert 
Attached is a zipped XML. I have obscured the database connection info - but If you want to see it live, I can privately give you a login/pw to the install.

thanks
empulse
Middleweight
Posts:81

08/21/2008 12:41 PM Alert 
I don't see that the attachment took. Not sure why, but am trying again.
pauldes
Immortal
Posts:1392

08/21/2008 12:49 PM Alert 
Try this and compare to your original.... you seem to be missing some single quotes in one of your if statements and the order of actions seemed odd to me so I reorganized it.

ListX....makes you look brilliant, even though you're not.
empulse
Middleweight
Posts:81

08/21/2008 5:12 PM Alert 
I did a little further cleaning (deleted extra indented actions) and made a small change to the insert statement. But it is still not working.

The execution seems to stop after the INSERT of UPDATE queries are executed. Whether successful or not, there is nothing listed in Debug view after the SQL query executes.

I am totally puzzled.
pauldes
Immortal
Posts:1392

08/22/2008 2:50 PM Alert 
I think it is your Action assignment names... I took the [] out of the names as they cause problems

See the attached. I reworked your module to change display names for the current portal where you can save them and update. It also shows you lxFetch which will ajax enable your module so you might want to review the attached configuration code.

Attachment: DisplayName.xml


ListX....makes you look brilliant, even though you're not.
robert_chumley
Please Wait...
Posts:595

08/25/2008 8:39 AM Alert 
Hey empulse,
Please let us know if this works for you.
Thanks,

Robert Chumley
r2integrated (formally bi4ce)
empulse
Middleweight
Posts:81

08/26/2008 2:23 PM Alert 
Not yet working (your example worked, but my form is a bit more comple). I am setting up another development instance of the application which I intend to make available publicly to those of you who are willing to take a look at it. First I have to get a mySQL connection string working.
You are not authorized to post a reply.
Forums > Bi4ce.Modules.ListX > General > Testing for successful insert



ActiveForums 3.6
Latest Post
 
At R2integrated (formerly Bi4ce), we take support seriously.  That's why we support our customers and DNN community with daily monitoring from our experienced engineering team.  We ask that the first step taken is to read the relevant documentation and support forums prior to submitting any questions that may already be available or have been answered.  We ask that you review the documentation that we provide for our products before posting a question.

The Forums are for our customers to chat, exchange ideas and strategies, and submit feedback.  Please be sure to perform keyword searches for previous related forum responses.

To be helpful when submitting a new item, please include the following: 
  1. DNN Version
  2. Module Version
  3. Admin Log Viewer Information
  4. Environment detail: Operating system, .NET framework version, database and version, IIS version, Browser version (if appropriate)
We always try to respond quickly and monitor the forums daily during business hours (EST).  Occasionally, requests for a specific project requirement may not apply for the free support offered. For project specific support please submit via our Information Request form.

Thank you for using our Forums.

Click here to register for the Forums
 
© 2008 by R2integrated (formerly Bi4ce) | DNN® is a registered trademark of DotNetNuke Corporation