1

I want to create keywords in HelpNDoc using api script editor. But, I could not find how to define parameter of function HndKeywords.CreateKeyword. Without passing any value to function, it create New keyword. But, I want to set text, href and data-related object informations.

HndKeywords.CreateKeyword;

Output:_keywords.json

[{ "id": "B3BF561185624A4685FB01E93FE5ED87", "parent" : "#", "text": "New keyword", "a_attr": {"href": "#", "data-related": "[]"} }]
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Premlatha
  • 1,676
  • 2
  • 20
  • 40

1 Answers1

2

I found that, there is no way to add caption and data-related information when we are creating the keyword.

function SetKeywordCaption(const aKeywordId: string; const sNewCaption: string): string;
function AssociateTopicWithKeyword(const aTopicId: string; const  aKeywordId:string): Boolean;

In order to edit the keyword caption, I have to use the function SetKeywordCaption, which needs keyword id. For that, I get the keyword list using function GetKeywordList(); and it returns an array. I get the last element numeric id from that array which is a newly inserted keyword. Then, access the aKeywordList array using last element array id and add .Id which will retrieve id of that keyword. Then, Using keyword id with function SetKeywordCaption, able to edit keyword caption.

In order to add data-related information, I have use function AssociateTopicWithKeyword which needs the topic id and keyword id. I get topic list using function GetTopicList. I get topic id of five(topic_array[(5-1)].ID) and sixth topic(topic_array[(6-1)].ID). Then, have used function AssociateTopicWithKeyword to link keyword to topics.

Call helpndoc function:

Object.function

ex (HndKeywords.CreateKeyword;)

var new_keyword                :=HndKeywords.CreateKeyword;
var aKeywordList                =HndKeywords.GetKeywordList() ;
//get keyword added last
var newlyaddedkeyword_array_id  =length(aKeywordList) - 1 ;
var newlyaddedkeyword__id       =aKeywordList[newlyaddedkeyword_array_id].Id;
var edit_keywordcaption         =HndKeywords.SetKeywordCaption(newlyaddedkeyword__id, "Edited keyword");
var topic_array=HndTopics.GetTopicList; 
var keywordtopics         =HndTopicsKeywords.AssociateTopicWithKeyword(topic_array[4].ID,newlyaddedkeyword__id);//parameter : topic id and keyword id
var keywordtopics2          =HndTopicsKeywords.AssociateTopicWithKeyword(topic_array[5].ID,newlyaddedkeyword__id);

See: HndKeywords - Properties and methods for keywords

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Premlatha
  • 1,676
  • 2
  • 20
  • 40
  • I suggest that you add a little xplanation along with your code snippet. I know it is fairly self explanatory but the SO team tend to dislike answers that are simply "code". This is why I atleast added a link to the official documentation for the `HndKeywords` API. – Andrew Truckle Apr 11 '22 at 07:17
  • Don't forget to accept your own answer ... to make it clear to other researchers a solution was found. – Andrew Truckle Apr 14 '22 at 07:36
  • This can be greatly simplified: `HndKeywords.CreateKeyword` returns the newly created keyword's ID. So you don't need to get a list of keywords afterwards and simply use `HndKeywords.SetKeywordCaption(new_keyword, "Edited keyword")` to set the caption of the newly created keyword. – jonjbar Apr 29 '22 at 07:53