Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eMatrix MQL question: passing BusObj and Context to execute program

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
I am tring to execute a program through MQL (Matrix Query Language) that seems to require a Context...
I use the format: execute program 'PROGRAMName'
and it returns an error...
Error: #1900068: execute program failed
Error: #1500125: Cannot execute program without a context
even if I do set the context.

Is there a way to pass the context to the progam as an argument? It also has to have someway of knowing what object it will be modifying... The specific program locks the object in matrix bypassing the CheckOut command, to alow checkin.

The program itself is contained in an object within eMatrix.

I would be very greatful if anyone can give me any explanation of how to do any of the above...

Thanks,
Josh S.

 
Hi Josh,

I think I have the answers or at least some of them.

1) if the program is "in" an object, that means that it is a method. Therefore, you should be able to extract certain information about the business object from the RPE (runtime program environment). Specifically, there are RPE variables that you either get by:

set sType [mql get env TYPE]
set sName [mql get env NAME]
set sRev [mql get env REVISION]

Matrix also provides "macros" to the TCL environment that sort of do the above for you, such as:

set sType ${TYPE}
set sName ${NAME}
set sRev ${REVISION}

either way works. You can look in the matrix online docs for the macros appendix and get the whole thing, including what macros (RPE vars) are available for every event that occurs in Matrix to businessobjects, relationships, policy state promote/demote events, and attribute modification events.

One final note: a method program object should indicate that it needs a business object in the program object defenition in the Business tool. This will ensure that the correct macros are there.

2) executing from MQL. You have to fenagle a method to run it as a 'raw' TCL utility program from MQL. First, the above macros WILL NOT BE AVAILABLE. Therefore, you must pass the type/name/rev info as arguments to the program. So to get:

<MQL> exec prog myProg.tcl Drawing 1234 A;

to pick up the args, when the main part of your program runs, (not in a PROC) you have to retrieve the args from the RPE either by:

set sType [mql get env 1]
or
set sType ${1}

etc.

You will have to turn off &quot;requires businessobject&quot; in the prog object def in the Business tool to make this work however, so you will have to change it again when testing as an actual method in the eMatrix tool so you can use the RPE vars TYPE/NAME/REVISION, etc.

To make your program more flexible, have it look initially for the RPE vars, and if they are not there, then look for the arguments. If neither is there, throw an error.

Also, check out the special TCL &quot;args&quot; argument. An alternative to using positional arguments in PROCs is to just pass &quot;args&quot;, then once in the PROC, foreach the $args (a list). When I do this I use name=value pairs, and provide defaults for all missing and optional arguments that the PROC recieves. So my proc call might look like:

set x [myProc &quot;sRev=A&quot; &quot;sType=Drawing&quot; &quot;sName=300600&quot;]

and my proc looks like:

proc myProc {args} {
foreach arg $args {
switch $arg ... (and match the args, supply defaults for missing optional args)
}
}

3) context. Sounds like you have not done:
set context user me password mypassword;
verb on;
or that somehow you are loosing context (ie: the program is trying to set context inside the code to a non existant user or with a bad password)

One trick you can use in your TCL program is to &quot;push&quot; and &quot;pop&quot; context. This approach is most often used when a trigger or other program must have access rights greater than that of your user. So you create a 'secret' user in the system (say with admin rights), push context to the admin user, do your thing, and then pop context to get back to the original user. BEWARE - this means that an administrative user's name and password are in the source code of your program. HOWEVER, as long as you are careful with admin privaledges, no unauthorized person should have the Business tool nor have access to view program code. So, be careful of who you dole our privaledges to.

4) context as argument. Shouldn't need to do it, but checkout the above (also not the RPE var USER). HOWEVER, you need to see what is going on inside that script and why you are loosing context. I HIGHLY recommend that you get the TCLPro debugger from:


and learn how to use it. This is a powerful tool and you really need it.

5) Object lock & checkin. You could do this as a business object method OR you could just create a CHECKIN trigger. Look in the matrix docs on triggers. There is are 3 kinds of triggers for each supported event:
CHECK - pre-event: make sure you want to let the event happen, or &quot;hard&quot; block if you don't
OVERRIDE - pre-event: make sure you want to let the event happen, or &quot;soft&quot; block if you don't & replace the event with your own event (this is a little tricky to figure out at first but is really powerful).
ACTION - post-event: after the event has happened (either a pass on the CHECK or a replace on the OVERRIDE) do you want to do something else to the object or related objects (such as connect relationships, etc.)

In your situation you may want to:
CHECKIN event - CHECK: is the busobj in the correct state? IF yes, then pass, IF no, then fail and notify user
CHECKIN event - ACTION: after the files are checked into the busobj, LOCK the busobj.

Hope this helps!

Regards,
John Lopez
mailto:consulting4matrix@hotmail.com
330.947.3800
P.O. Box 290
Deerfield, Ohio 44411 John Lopez
Enterprise PDM & Integration Consulting
Development for MatrixOne PDM Systems
johnlopez2000@hotmail.com
 
John,
How did you say to dump the contents of the tcl/tk program in the method within matrix?

(to dump the source code) Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
OK, NM, I found it...
<MQL> print program ProgramName.tcl select code output c:/ProgramName.tcl;
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
OK...

I am using VB... With Matrix PDM via MQL (MatrixQueryLanguage)...
Trying To run a Tcl program that is in Matrix with VB...
I am using an MQL command...
execute program 'ProgramName'
and get the &quot;Cannot execute program without context&quot; error.

I CAN view the code... using Print Program...
And I can set the context...
But It still won't let me execute the program (method)

If there are any other mql users out there...

are there any other ways to execute programs / methods with mql and VB

I am using MQLVB32.dll Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Hi QB,

when you connect to MX via MQLIO, you have to do a:

set context user XYZ pass ABCD;

just like you would in a regular MQL session.

When you initially connect, you are logged in as &quot;guest&quot; but have no real privaledges.

Give the above a try.

John Lopez John Lopez
Enterprise PDM & Integration Consulting
Development for MatrixOne PDM Systems
johnlopez2000@hotmail.com
 
Thats what I tried...
Even...
set context user 'XYZ' pass 'ABCD'; execute program 'MyProgram'

It sets the context... (You know this because it returns 0 - No Data) if the context does not set it returns 2 - error

I believe the problem is...
In thick client... (matrix.exe) you use the mouse to select items.
When a program (method) is executed it has access via macros (Like you said before) to the item selected in matrix and the context that is set...
According to the hep file... This...
output &quot;The value of \${USER} is ${USER}&quot;
Should work...
As per...
* Macro Processing and Command Syntax

For example, if USER=guest then:

output &quot;The value of \${USER} is ${USER}&quot;

results in the output:

The value of ${USER} is guest

I could not get this to work (I am not at work right now so I can't play with it at the moment)
Is this inside of a program (tcl/tk code) or just a mql command that you can execute from anywhere...

Also...
I know you can use
Set Context User 'BlaUser' Password 'BlaPass'
but can you set the selected object the same way???
such as...
Set Context Type 'myType' Name 'myName' Revision 'myRev'
So that when the program looks for $(type) $(name) and $(revision) it will have something to read from?

Ok...
I think i MIGHT have answered my own question(I'll find out monday)...
from:
* Handling Variables > Using the Runtime Program Environment

RPE and Tcl are closely integrated: you can set Tcl variables with RPE variables (using set var [mql get env NAME]) and set RPE variables with Tcl variables (using mql set env NAME $var). Of course, the VARNAME field itself can also be a Tcl variable.

So...
If I am reading this right...
You can set Context with set context user 'U' password 'P'
Then set The 'T' 'N' 'R' with set env type 'T' name 'N' revision 'R'
...or something to that extent...
If you have any suggestions... PLEASE LET ME KNOW.

Also FYI: I found this on the web if you need to access the help away from work or what ever...
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
OK...
I pulled up the TCL/TK code... from matrix...

It IS calling this...
Code:
set defUser &quot;${USER}&quot;
...
set szType [ mql get env TYPE ]
set szName [ mql get env NAME ]
set szRev [ mql get env REVISION ]
...
set szID [ mql get env OBJECTID ]
if { $szID == &quot;&quot; } {
  set szID [ mql print bus &quot;$szType&quot; &quot;$szName&quot; &quot;$szRev&quot; select id dump ]
}
so I bet that is how you set those Var's...
I'll try it and let you know...
It might be good to know for future reference... Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
That is how you set the ENViroment Var's...(BTW)

This Is DRIVING ME KRAZY...

I can set the context &quot;set context user ABC password 123&quot;...
I can set the env variables &quot;set TYPE abc;set NAME 123;set REVISION A&quot;...
I can type &quot;print context&quot; and it returns my context info...
So I know the Context IS Set...
I can type &quot;get env TYPE&quot;,&quot;get env NAME&quot;,...
It returns the info I set... So I know those are set...

...And I still get the context error when I use &quot;execute program ABC&quot;...

*Note: ABC's and 123's are place holders for information that could result in conflict of interest and/or confidentual info. The REAL user, pass, and env variables I am using are preset, existing company info.

What Else Could I Possibly Need To Set??? Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
QB101,

here's the deal (i think).

TYPE,NAME,REVISION,USER, etc. are TCL macros & they are also env vars.

The systems sets these and you can't trick it. I tried this with INVOCATION, to get it to run non-derefed trigger code, and it just won't work.

The above env vars and subsequent macros (like: ${TYPE}) are set at runtime by the system.

The above code must be execing as either a METHOD or TRIGGER. When a method/trigger execs, it does so against the selected BO in the GUI env.

The way to do this in MQL (and it MUST work in MQL before it will work in VB/MQLIO), is that the above method must be exec'd as:

mql execute bus ${TYPE} ${NAME} ${REVISION} ...

(in MQL do: help bus; to get all the params)

THIS WAY, the BO IS SELECTED & THEREFORE the ENV vars will be populated by the system.

In Matrix online help go to the MACRO APPENDIX to find out what macros are created by the system under which conditions. You can't or at least shouldn't trick it. The RPE is a very controlled environment and you should work within the controls that Matrix gives you to get consistent performance.

ANOTHER THING TO CONSIDER regarding context. SOMETIMES you do not have all the privaledges taht you need to do what you want. THEREFORE, look into &quot;push/pop context&quot;. Create an &quot;admin user&quot; who has lots of privaledges, and at the top of the program &quot;push context&quot; to that user. Then your high profile stuff will work. Before you leave, &quot;pop context&quot;. THIS IS BETTER THAN &quot;set context&quot; in your program. The reason is that should the program fail, &quot;set context&quot; will leave your connected user as the ADMIN USER - bad deal. &quot;Push context&quot; will reset them to their login, even if program failure occurs and the program does not gracefully &quot;pop context&quot;.

Final word: MACRO APPENDIX.

Good luck. Hope this helps.

John Lopez
John Lopez
Enterprise PDM & Integration Consulting
Development for MatrixOne PDM Systems
johnlopez2000@hotmail.com
 
OMG!!!

It finnally works...

THANKS ALOT...

execute businessobject BO_NAME method METHOD_NAME [ARG {ARG}];
(what are the arg(s))

execute bus 'T' 'N' 'R' method 'MethodName'

I knew it was a method... I just couldn't figure out hoew to execute a method...

I know you can do: mql temp query bus T N R select
and at the bottom of the dump it list the methods you can use on the given object...

and you can do print program 'Name' select isamethod
and it will return: isamethod = TRUE

I didn't know about help bus either...
you can also do help program... help etc...
I wish I knew that 6 months ago ;-)

Also if an object has no rev... is the BO_NAME just 'T' 'N' ?

I think I can leave you alone for a while now...

Thanks Again... Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Noooooooooooooooooooooooooooooooooo problem!

John Lopez John Lopez
Enterprise PDM & Integration Consulting
Development for MatrixOne PDM Systems
johnlopez2000@hotmail.com
 
CubeE101 - just thought I'd check in and see how your Matrix efforts are going!

have a good one!

John Lopez
Enterprise PDM Architect
lopez.john@goodrich.com
 
It's going pretty smooth now, thanks for your help...

I probably would have never thought to use:
exec bus T N R method 'MethodName'

to execute a method (program)

I was wondering if there is a way to pass arguments to the method using this command...

For example: we have our system set up to where we have Work Auths, tasks, and project roles...

the tasks are created by selecting a Work Auth and executing the method which then requires a project role

so I was wondering if there was a way to pass the project role to the method...

the help command has been a big help also...

I developed a little app in vb to test mql commands, it consist of aprox. 10 input lines each with it's own execute button and an output textbox and a status text box to show the status of the return data (OK, Error, No Data...), along with a few other features... it works great for building and debuging mql commands on the fly and testing different variations of commands...
I also added a feature where you can export/import the commands to/from a text file so you can save them then come back and modify them...

I also made a bunch of little excel macros that use mql...
You can have a list of part numbers, select a set of them and click a button, and it will execute a set of cammands on each one and place the formated return data next to it, which ends up saving alot of time as opposed to esecuting the commands on each individual item...

Thanks again for all of your help, I would give you the other 4 stars if it would let me ;-)

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top