Welcome to the COE Discussion Forum! 

 

To participate in the discussion forum, you must be logged in to the website.  If you forget your login information, please contact COE Headquarters at coe@coe.org or (800) 263-2255.

If you are new to the COE Discussion Forum and would like to participate, please register.


Register Today
COE 2009 Annual PLM Conference & TechniFair

COE DISCUSSION FORUM
Subject: Updating database at AFTER ADD Script Hook

You are not authorized to post a reply.   
Author Messages
chaya.hk

05 Nov 2008 10:46 PM

Hi All,

Iam using ST R18/ SmDemo. I have hooked a script at ADD/AFTER for Documents class which has to update the field "Item Number". My script is failing at updating the database, though it does not pop up any error/warning message.

I have pasted the script for your reference. Please suggest.

    Set SmSession = SCREXT_ObjectForInterface(ApplHndl)
    CONV_RecListToComRecordList FirstPar, Record1
    CONV_RecListToComRecordList SecondPar, Record2
    CONV_RecListToComRecordList ThirdPar, Record3

 Dim ObjectStore As ISmObjectStore
 Set ObjectStore = SmSession.ObjectStore

 Set SmRec = Record1.GetRecord(0)

 Set SmObject = ObjectStore.ObjectFromData(SmRec,True)

    serial_num =  SmObject.Data.ValueAsString("CN_SERIAL_NUM"
    subassy =  SmObject.Data.ValueAsString("CN_SUBASSY"
    future_use =  SmObject.Data.ValueAsString("CN_FUTURE_USE"
    var =  SmObject.Data.ValueAsString("CN_VARIANT"

 part_num = subassy + future_use + serial_num + var
 

    Record3.AddHeader "CN_PART_NUMBER", 20, sdtChar
    Record3.ValueAsString("CN_PART_NUMBER", 0) = part_num  *

* not working

CONV_ComRecListToRecordList Record3, ThirdPar

Thanks in Advance

Chaya H K

 

 

 

EMAGNETTO

10 Nov 2008 05:54 AM
The problem is that on "AFTER XXX" hooks data has been commited to DB and you cannot modify attribs on thi way.
You have two options:
* If you can move your script to BEFORE hook (will depend you your business rules), this methodology will work.
* If you can't, you don't return anything on the Third Rec. You must use the Update method of SmObjects after you update the attributes: SmObject.Data.ValueAsString("CN_PART_NUMBER")=part_num
SmObject.Update

If this gives you errors, you must clone the object on creation.

Regards,
Eduardo
chaya.hk

14 Nov 2008 01:25 AM

Thanks for the reply.

I tried using SmObject.Update but it gives an error "Property Not found"

Could you please brief me about the other option you have suggested "Clone on Creation".

A sample piece of code will be very much appreciated.

Thanks in advance

Regards

Chaya

 

 

EMAGNETTO

18 Nov 2008 08:44 AM

There are many ways to retrieve an object and update.
The most efficient (though longer) is to retrieve only the information you need from the object.
There are shorter samples, but this should work.

My code was written on VB.NET, so there may be slight differences if you write just a script. I think you won't have problems to adapt.

Let me know if you have problems. On this example I don't use the clon method. I think it won't be neccesary. If you have problems, let me know.

Eduardo

********************************************************

'I get the object, without any attributes (just CLASS_ID and OBJECT_ID)
Dim oSmObject As ISmObject
oSmObject = oSmSession.ObjectStore.NewObject(Record1.ValueAsInteger("CLASS_ID", 0))
oSmObject.ObjectId = Record1.ValueAsInteger("OBJECT_ID", 0)

'Here I set just requires attribs to retrieve
oSmObject.AddAttributes("TDM_ID"
oSmObject.AddAttributes("CN_PART_NUMBER"
oSmObject.AddAttributes("CN_SERIAL_NUM"
oSmObject.AddAttributes("CN_SUBASSY"
oSmObject.AddAttributes("CN_FUTURE_USE"
oSmObject.AddAttributes("CN_VARIANT"

'And retrieve information
oSmObject.RetrieveAttributes()

'Now the logic to build the Part Number
serial_num =  oSmObject.Data.ValueAsString("CN_SERIAL_NUM"
subassy =  oSmObject.Data.ValueAsString("CN_SUBASSY"
future_use =  oSmObject.Data.ValueAsString("CN_FUTURE_USE"
var =  oSmObject.Data.ValueAsString("CN_VARIANT"
part_num = subassy + future_use + serial_num + var

oSmObject.Data.ValueAsString("CN_PART_NUMBER" = part_num

oSmObject.Update()

********************************************************

You are not authorized to post a reply.
Forums > COE Forums > SmarTeam > Updating database at AFTER ADD Script Hook



ActiveForums 3.6

    

401 North Michigan Avenue, Chicago, IL 60611-4267 | (312) 321-5153 | (800) COE-CALL (U.S.)