cancel
Showing results for 
Search instead for 
Did you mean: 

How to add new card as related document in another card?

etoropov
Champ in-the-making
Champ in-the-making
Hello,

Could you plz to help me - I have two type of cards, for example.
In 1st type I have assotiation for relatedDocument.
I want follow: when I am creating 2nd card it's needed to choose 1st card (from some list with values ​​of name first type of cards on this card) and add to the this card link (as related document)

By what means(java as I understand) can I do this?

Thx a lot
5 REPLIES 5

mitpatoliya
Star Collaborator
Star Collaborator
When you say card I guess it is nothing but your custom content type right?
There is concept of association in where in the content model you can specify the association.
So all you need to do is while definining  the second content type (Card2 ) in the content model just define the association along with that  so when ever you will create the card2 you can always associate it with the already crated contents of type1(card2).
You will also require to do the changes in the web-client-config-custom.xml

etoropov
Champ in-the-making
Champ in-the-making
Yes, you'r right.

It's my model:

   <types>
      <type name="sc:carinfo">
         <title>car info</title>
         <parent>cm:content</parent>
         <properties>
            <property name="sc:carinfo1">
               <title>ci_field_1</title>
               <type>d:text</type>
            </property>
            <property name="sc:carinfo2">
               <title>ci_field_2</title>
               <type>d:text</type>
            </property>
         </properties>
         <associations>
            <association name="sc:relatedDocuments">
               <title>rel_doc</title>
               <source>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </source>
               <target>
                  <class>cm:content</class>
                  <mandatory>false</mandatory>
                  <many>true</many>
               </target>
            </association>
         </associations>
      </type>

<type name="sc:leasing">
   <title>leasing</title>
   <parent>cm:content</parent>
   <properties>
      <property name="sc:leasing1">
      <title>l_filed_1</title>
      <type>d:text</type>      
   </property>
      <property name="sc:leasing2">
      <title>l_filed_2</title>
      <type>d:text</type>      
   </property>
      <property name="sc:leasing3">
      <title>l_filed_3</title>
      <type>d:text</type>      
   </property>


I created rules for folder (where I created new content leasing) for executing script when file is placed to this folder:
var insp = document.properties["sc:leasing2"];

results = search.luceneSearch(insp);
for (var i = 0; i<results.length; i++){
    document.createAssociation(results[i], "sc:relatedDocuments" );
}
document.save();


When I created 1st card (carinfo) in the ci_field_1 I type "111".
In the 2nd card I type "@sc\:carinfo1:111" to l_filed_2 (sc:leasing2)
I think that script should be found card carinfo with filed sc:cardinfo1=111 and createAssociation with new leasing card. But I have error:

Failed to create content: 04158106 Found 1 integrity violations:
   The association source type is incorrect:
    Source Node: workspace://SpacesStore/ec8d98ec-b7c3-4c82-9977-0e5b257d0d2a
    Association: Association[ class=ClassDef[name={http://www.someco.com/model/content/1.0}carinfo], name={http://www.someco.com/model/content/1.0}relatedDocuments, target class={http://www.alfresco.org/model/content/1.0}content, source role=null, target role=null]
    Required Source Type: {http://www.someco.com/model/content/1.0}carinfo
    Actual Source Type: {http://www.someco.com/model/content/1.0}leasing

where is my mistake?

mitpatoliya
Star Collaborator
Star Collaborator
As shown in the error you are trying to create the associate first cardtype with the leasing card.Where leasing is your source but as per the content model it should be opposite of that.
You need to invoke the rule of creating association while uploading the document of type1(cardinfo1).
And associate leasing type document with that.
You are doing exact opposite of that right now.

etoropov
Champ in-the-making
Champ in-the-making
No, this is the logic
There is already exist card with type1 (carinfo) and sometime after there is need to create new card with type2 (leasing). And this card(type2) should be doc as related document for card with type1.
How to do this?

etoropov
Champ in-the-making
Champ in-the-making
Oh, sorry, you are absolutly right

var insp = document.properties["sc:leasing2"];

results = search.luceneSearch(insp);

for (var i = 0; i<results.length; i++){
    results[i].createAssociation(document, "sc:relatedDocuments" );
}
document.save();

Thanks!