What is formula that can handle two situations

I am thinking of a view that can open doc or create a new doc. What I need is action in formula check if doc is exist in DB or not. If doc is not exist in DB, then create a new doc. If doc is exist in DB, then open current doc. what is formula can do that?

Subject: what is formula that can handle two situations

I tried my code here, I can get UNID, but cannot open doc because it shows error msg saying" Entry not find in index. Any idea?

lookup:=@DbColumn(“”:“ReCache”;“”;“DatabaseSetup”;1);

@Prompt ([Ok];“ID”;lookup);

@If(@IsError (lookup);@Command([Compose]; “”; “DatabaseSetup”) ;@Command([OpenDocument];“”; lookup))

Subject: RE: what is formula that can handle two situations

It’s not really clear what you are actually trying to achieve in the end, but I’ve spotted a problem with that code snipped you pasted.

lookup:=@DbColumn(“”:“ReCache”;“”;“DatabaseSetup”;1);

This line of code is retrieving the entire first column of values from your DatabaseSetup view. You are then trying to use this list of values as the ‘unid’ parameter of @Command([OpenDocument]) . This is never going to work - you probably want @DbLookup if you’re trying to retrieve a single value from the column.

If you can explain more precisely what you want to acheive, maybe we can help you some more.

Emily.

Subject: RE: what is formula that can handle two situations

I created a outline. in an entry, I label it as Database Setup, and then select “Action” in Content type. I do not want to select “Named Element” to open form (because it alwasy open new doc). I wrote the code in Action formula. Then I created two frames and a frameset. Left frame has a outline that can open/create doc in Right frame. so, when I click a view in left frame, right frame is supposed to open doc if doc is exist, or create a new doc if doc is not exist. the DB has a database Setup view, but it is hidden. It is not matter to use @DBColumn or DBLookup. I can get UNID before formula check exist doc. I tried my code, but still not work…:frowning:

lookup:=@DbColumn(“”:“ReCache”;“”;“DatabaseSetup”;1);

@Prompt ([Ok];“ID”;lookup);

@If(@IsError (lookup); @SetTargetFrame (“RightFrame”) & @Command([Compose]; “”; “DatabaseSetup”); @SetTargetFrame (“RightFrame”) & @Command([OpenDocument] ;“”;lookup))

Subject: RE: what is formula that can handle two situations

I’m not certain, but it sounds like you want the database to have one and only one document for “database setup” information. Is that the case? If so, what you want is a profile document.

Subject: RE: what is formula that can handle two situations

Thanks so much. I tried @Do(

@SetTargetFrame (“RightFrame”) ;

@Command( [EditProfileDocument];“DatabaseSetup” ))

But it did not open doc in RightFrame. Just open a entire doc. Any idea?

Subject: RE: what is formula that can handle two situations

I think you’re making the formula more complicated than it needs to be. You can set a target frame for the individual outline entry or for links in the frame as a whole. Try either of those and get rid of the @Do and @SetTargetFrame.

Subject: RE: what is formula that can handle two situations

Well. I am selected “Action” type for the individual outline entry, it is no way for me to set a target frame. Only “Named Element” type, I can set target frame. but I donot want that way, because Name Element type alwasy open new doc. I tried Link type, it is only set Target frame, but it is no way for me to set up whick form will be opened.