spacer
cornerspacercorner
Reply
Regular Advisor
RKushner
Posts: 103
Registered: 05-20-2010
0 Kudos
Accepted Solution

Please help writing SQL in JScript.

I need to delete rows from the database when the user cancels out of a form. While in the form, the user may insert rows into a grid, and this is done by a database row insert which doesn't automatically roll back when the user cancels the form.

 

Can someone please tell me how to put simple sql into JScript and/or just share an example?

 

Many thanks!!!!

 

Rick

Frequent Visitor
kanangela77
Posts: 2
Registered: 06-02-2011
0 Kudos

Re: Please help writing SQL in JScript.

Try this:

 

function deleteRows()

{

ework.SelectSQL("DELETE FROM [tablename] WHERE [columnname] = '" + ework.[variablename] + "')",[DSN]);

}

 

Just replace everything inside the [ ] with your custom info.

 

Regards,

Karen Frazier

Regular Advisor
RKushner
Posts: 103
Registered: 05-20-2010
0 Kudos

Re: Please help writing SQL in JScript.

Great, thanks!!!
Frequent Advisor
DSmith
Posts: 37
Registered: 06-23-2010
0 Kudos

Re: Please help writing SQL in JScript.

This is correct except for you have to use EXECSQL,for update, delete and insert statements

and DSN has to be in quotes " "

, but if your deleting tables in the metastorm database, not DSN is needed.

Frequent Visitor
kanangela77
Posts: 2
Registered: 06-02-2011
0 Kudos

Re: Please help writing SQL in JScript.

I was not aware that a DSN wasn't required for a DELETE statement. Thanks!
Regular Advisor
RKushner
Posts: 103
Registered: 05-20-2010
0 Kudos

Re: Please help writing SQL in JScript.

Yes, thanks. I am using the default metastorm database.
Occasional Contributor
jkessler
Posts: 5
Registered: 07-08-2010
0 Kudos

Re: Please help writing SQL in JScript.


kanangela77 wrote:

Try this:

 

function deleteRows()

{

ework.SelectSQL("DELETE FROM [tablename] WHERE [columnname] = '" + ework.[variablename] + "')",[DSN]);

}

 

Just replace everything inside the [ ] with your custom info.

 

Regards,

Karen Frazier


I am trying to do something similar but this isn't working for me, I get "ework is undefined".  

 

Here is the code I am using:

var countDependents = ework.SelectSQL("select count(distinct(depid)) from ew_mrpbs.isdependentprofile where pin = '"+pin+"' and ACTIVE_FLAG = '"+activeFlag+"'");

 

 

I am using a client side validation script that runs on submit on a form.

Valued Contributor
BMellert
Posts: 177
Registered: 05-21-2010
0 Kudos

Re: Please help writing SQL in JScript.

The ework.SelectSQL approach only works in server side scripts.

 

I am unsure how to do that client side directly.  When we have similar needs as I think you're trying to accomplish, we have a client script do client side stuff (are you sure? kind of thing).  Then we do buttonClick(serverbutton) which is a hidden server side containing the other code (delete in your case).

 

Another possibility, again depending on exactly what you're trying to accomplish, may be to have your client validation do <stuff> and then on the when user saves form handle the delete.  If the client stuff fails (e.g. they click cancel on a validation or something) then the server side shouldn't fire off.

line spacer line
spacerFollow Metastorm on:
spacer Twitter YouTube Blog iTunes LinkedIn Metastorm Community Central, MC2
spacer Copyright © 2011 OpenText Corporation. All Rights Reserved.spacer About Metastormspacer Privacyspacer Legalspacer Site Mapspacer RSSspacer Contact Us
Microsoft Gold Certified Partner
Powered by Windows Azure
line spacer line