This question about Topic Markup Language and applications: Answered

Macro used in a formfield to get the Topic where the Dataform is attached

Hello, I want to create "AutoincTopics" with a Dataform attached. One Formfield of the Dataform should be filled automatically with the topic where the dataform is attached. But when I use the Macro Question2056 I only get the topic name of my dataform and not the name of the Topic, where my Dataform is attached. Can you help me?

This is the code that I use:
%BUTTON{
    "%MAKETEXT{"Create a  new Labbookentry"}%"
icon="add"
target="%SCRIPTURLPATH{edit}%/%WEB%/Elab%USERNAME%AUTOINC00001?formtemplate=StartForm;templatetopic=ElectronicLabnotebookTemplate;topicparent=%TOPIC%;t=%SERVERTIME{"$day$hour$min$sec"}%][Create a new Labbookentry"}%%CLEAR%

-- AbhilashaKerkmann - 13 May 2020

Why would you want to store the topic name into a formfield? I virtually cannot imagine any situation where that would be of any use...

-- MichaelDaum - 13 May 2020

What I think Michael is saying here is that the topic name itself is aways available and easily referenced via macros like %TOPIC% or $topic parameter within SEARCH (or other macro/plugin) output, so storing it in a field would be redundant.

-- LynnwoodBrown - 13 May 2020

I know this question sounds strange but it can help me a lot with query searches. It is complicated but I try to explain:

I need this, because we want to create different Proteinconstructs with a unique ID. This ID we want to define by the autoincrement through topic creation. I want to use this number for a query search in combination with other formfields. I am using this ID for different dataforms.

For example I created via Autoinc Pages that discribe one Protein. Keywords are stored in a dataform. Later I want to create via Autoinc Pages that discribe different variation of the Protein, called construct pages. I also want to visualize ProteinPage ID in the table construct page (Tables are created by query search). Now it would be easier if I could use in the Searchfunction format=$formfield(ID) in combination with the proteinname from a special dataform. But therefore I need to get the name of the topic defined as ID into the formfiled.

Table1: Topic Proteinname ProteinPage00001 MagY ProteinPage00002 MagK

The Protein MagY will get different attributes, so I will create new topics.

Table2: Topic Proteinname Construct ID Constructpage00001 MagY ProteinPage00001 Constructpage00002 MagY ProteinPage00001 Constructpage00003 MagK ProteinPage00003

-- AbhilashaKerkmann - 13 May 2020

I hope the table looks better now:

Table 1:

Topic Proteinname
ProteinPage00001 MagY
ProteinPage00002 MagK

Table2:
Topic Proteinname Construct ID
ConstructPage00001 MagY ProteinPage00001
ConstructPage00002 MagY ProteinPage00001
ConstructPage00003 MagK ProteinPage00002
-- AbhilashaKerkmann - 13 May 2020

That's very helpful. I'm getting a clearer idea about what you're trying to do. Am I correct in understanding that the part of the topic name that you're really wanting to capture is the number generated by AUTOINC (e.g. 00001, 00002, etc)? I understand now why it would useful to capture that number in a form field but I don't have an idea how to do it at the same time as the topic is being created.

I do have ideas how you can grab that number to use in a search or form to create related records using either SpreadSheetPlugin or FilterPlugin. I use FilterPlugin a lot as it's very useful for this kind of thing. You could use the EXTRACT macro like this:
%EXTRACT{text="Question2056" pattern=".*?(0-9)+" format="$1"}%

You could do a similar thing using SpreadSheetPlugin like this (assuming the number part of topic name was 5 digits):
%CALC{"$RIGHTSTRING(Question2056, -5)"}%

Let me know if either of these would work or my solution needs clarification or if I'm still off base.

-- LynnwoodBrown - 13 May 2020

Have a look at Extensions.MoreFormfieldsPlugin: it can extract the number from an autoinc topic into a formfield using the id formfield type. In addition it can generate autoinc formfield values independent of the topic name using the autoinc formfield type. This also covers use cases when a single topic needs multiple unique numbers coming from different sources.

-- MichaelDaum - 14 May 2020

Hello, it´s me again. I like the idea with the CALC-Function. It works on the current page (with using 5 instead of -5). But my searchfunction is on another page. (lets call it TestPage) So my format output does not show me the extracted number from the original page, it shows me the last 5 values from the current page-> tPage

How can I avoid this problem? Somehow I need to transfer the variable value of the Macro into a string or into a static lable after the topic is saved.

I also tried to use the EXPAND Macro, but for the scope I need to know the specific topic name. Because of the specific topic name it does not help me, since I need to extract the information of the DATA-FORMS of all my, via AUTOINC, created pages:
%EXPAND{ "  $percentSEARCH{ 
$quotConstruct$quot  
scope=$quottopic$quot
nonoise=$quoton$quot  
sort=$quoton$quot  
excludetopic=$quotConstructpage*,ProteinConstruct*,*Template*,PAConstructs $quot  
header=$quot | *Topic* |*date*| *Proteinname* |*ID*|  $quot  
format=$quot | [[$topic]] |$percentDATE$percent | $formfield(Proteinname) | $formfield(ID) |   $quot  
footer=$quot | *Topics found* | *$ntopics* |||   $quot   
}$percent "  scope="Construct00001" }%

I tried to replace the scope="Construct00001" with a search function that gives me all the topics seperated by a comma. Then I get the message: EXPAND failed - no such topic 'Construct00001 , Construct00002 , Construct00003 '

Is there a way to extract the value of the MACRO from the original page first, before the Search-function gives me the output?

-- AbhilashaKerkmann - 26 May 2020

Abhilasha - I need help understanding the the relationships between the topics to sort out the context of the variable expansions. Let me see if I have this right:
  • Base topic - this is the topic being viewed and whose name you want to extract the 5 digits from. This topic has a button in it for creating new topics that refer back to the base topic.
  • Page containing SEARCH - this is used via an INCLUDE or some other mechanism (such as a macro or view template). Please tell me if it's not an INCLUDE as that would affect how the macros are expanded.

Please confirm if the above is correct and then clarify where the CALC macro is. I don't see it in your example above. Is the CALC macro inside the search?

-- LynnwoodBrown - 26 May 2020

I have a Topic (=ConstructOverview) with a button to create via AUTOINC several pages, with a special DataForm attached. These topics are called ConstructPage00001, ConstructPage00002, ConstructPage00003 ..). On the Topic "ConstructOverview", I use the SEARCH-Function, to view all the information from the DataForm of each ConstructPage. One formfield has the name ID, this has the CALC-Function. It extracts the number 00001, when I am on the Topic ConstructPage00001. My SEARCH-Function used on the Topic "ConstructOverview" gives me for the formfiled ID the value rview, because %TOPIC% in %CALC{"$RIGHTSTRING(Question2056, -5)"}% seems to be only related to the current topic, that is ConstructOverview now. ( To use =%BASETOPIC% instead of =%TOPIC% also does not helped) I am not using INCLUDE Only SEARCH:
%SEARCH{ 
 "ConstructPage" 
 scope="topic"
 nonoise="on"
 sort="on"
 excludetopic="ConstructPageTemplate"
 header="| *Topic*        |*date*| *Proteinname* |*ID*|"
 format="| [[$topic]]     |27 May 2020  | $formfield(Proteinname) | $formfield(ID)  | "
 footer="| *Topics found* | *$ntopics* |"
}% 

THe CALC-Macro is indirectly inside the SEARCH when using format = "$formfield(ID)", because the ID-Formfield on the ConstructPage00001 has this function.

-- AbhilashaKerkmann - 27 May 2020

My apologies if I'm being a bit dense here but I'm still having a hard time understanding exactly how the ID-Formfield is figuring in all this. It appears to me that you are simply trying to extract the numbers from the end of the names of the topics found by your search. I believe this can be done with this search (putting the CALC macro inside search results):
%SEARCH{ 
 "ConstructPage" 
 scope="topic"
 nonoise="on"
 sort="on"
 excludetopic="ConstructPageTemplate"
 header="| *Topic*        |*date*| *Proteinname* |*ID*|"
 format="| [[$topic]]     |27 May 2020  | $formfield(Proteinname) | $percntCALCULATE{\"$RIGHTSTRING($topic, -5)\"}$percnt  | "
 footer="| *Topics found* | *$ntopics* |"
}% 

Regarding the ID-Formfield on the ConstructPage00001, are you saying that you have that field set up using the CALC macro as the field value? If that's the case, I don't think it's serving any purpose since it might display the correct value, but it's not storing that value, hence there's no way to query it.

I hope we're getting close to the answer you're looking for! smile

-- LynnwoodBrown - 27 May 2020

Dear Lynnwood,

thank you, to enter the CALC-Function into the format helps me a lot to get the nr. It is a really interesting way to get this information. You understand me totally right, the ID-Field is set up using the CALC macro as the field value, to grap some information automatically. Yes the problem seems to be, that the value is not stored that is why my search is not working like I wish. I have other cases where I use a Macro predifined in the Dataform like this:

Name
Type
Size
Values
Tooltip message
Attributes
Default
Status
text
50
 
 
 
 
Construct#
select
1
%TOPIC%
 
 
 
Proteinname
select
1
%SEARCH{  "ProteinPage"   scope="topic"   nonoise="on"   sort="on"   excludetopic="ElectronicLabnotebookTemplate, AKElectronicLabnotebook, ElabAbhilashaKerkmannTemplate"   format="   $formfield(Proteinname)"   separator=", "   }%
 
 
 
Databanknumber:
select
1
%SEARCH{ "MyproteinForm.Proteinname='%MAKETEXT{%SEARCH{ "%TOPIC%" scope="topic" pagerformat="Page $currentpage" type="field" nonoise="on" format="$formfield(Proteinname)"}%}%'" type="query" web="%WEB%" format=" $formfield(ID) " nonoise="on" }%
Tag
text
50
Additional information
text
50
I have a DataForm called MyproteinForm. Some of the values are called Proteinname and Databanknumber. They will be entered manually. Then I have another Dataform PaConstructs. There I can select the proteinname, because the value is a SEARCH-Function like you can see above. When I select a Proteinname, then it will automatically show me a Databanknumber, that is connected to the proteinname with another SEARCH-Function.

It is a pitty, that Macros are not stored, that I can query them. I thought VarEXPAND can help me to pick up the value of macros defined in another topic. In general EXPAND works, but the problem is I can scope only one topic. But my table is the result of several topics.

It would be great If Foswiki can store the Value somehow in the future, by adding an attribute or something like this. In the Dataform I can not use as type Label (this could help to store the value) because this would be to early, like for example my AUTOINC only shows me the final Topic number after it is saved. On the beginning it is always BUGAUTOINC00001 .

I am sorry for bothering you so much. I appreciate your help and all the time you spend allready for helping me

Thank You

-- AbhilashaKerkmann - 28 May 2020

I'm glad my suggestion was helpful. Now that I understand what you're trying to achieve by storing that macro in the field, I believe MichaelDaum pointed to you a very workable solution. Take a look at MoreFormfieldsPlugin id field type. It does exactly what you're asking for in terms of result.

As for storing a macro, what I really think you're saying is storing the output of a macro and that can be done in different ways in Foswiki. The AUTOINC feature in saving a topic is a bit "unique" as it's hard to know the value before hand. But that's exactly where the id field type comes in handy.

-- LynnwoodBrown - 29 May 2020

Dear Lynnwood, MoreFormfieldsPlugin id field type is helpful, but only to get the ID.

I am a big friend of using Macros as a value in a dataform.

Nevertheless I got a lot of inspiration to work around my problem, that I can not query a formfield that use a Macro as a value.

It is a little bit complicated but it worked.

Thanks for your help!!!

-- AbhilashaKerkmann - 29 May 2020
 

QuestionForm edit

Subject Topic Markup Language and applications
Extension
Version Foswiki 1.1.4
Status Answered
Related Topics
Topic revision: r13 - 29 May 2020, AbhilashaKerkmann
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy