cancel
Showing results for 
Search instead for 
Did you mean: 

ECTR macro: Filter by DRAD values?

Hi all,

Is it possible to filter a document selection in a macro by values of the DRAD table?

The goal is to filter documents without exclusive material links in a macro.

This is what I got so far (it is not working):

function filter_selected_docs() {
    // get the active selection (documents only)
    KL_Selection = KEYLIST_FROM_CONTEXT("active", "selected", "doc");
    if(KL_Selection.length > 0) {
        set_Selection = CREATE_SET(KL_Selection);

        // filter all documents with material link
        p_Filter1 = PARAMETER_MAP("doc_filter_fields");
        p_Filter1.HASMATERIAL = "X";
        set_Filter1 = FILTER(set_Selection, "doc", p_Filter1);
        
        // check if there are still documents to check
        KL_WithMaterialLinks = KEYLIST_FROM_SET(set_Filter1);
        if(KL_WithMaterialLinks.length > 0) {
            // filter all documents with an exclusive material link
            // note: this will return both, documents with multiple material links
            //       and documents with only one material link
            p_Filter2 = PARAMETER_MAP();
            p_Filter2.OBJECT_TYPE ="DRAW";
            p_Filter2.TABLENAME = "DRAD";
            p_Filter2.FIELDNAME = "CAD_POS";
            p_Filter2.SIGN = "I";
            p_Filter2.OPTION = "EQ";
            p_Filter2.LOW = "X";
            set_Filter2 = FILTER(set_Filter1, "doc", p_Filter2);

            // remove all "good" documents from the list
            set_Filter3 = OPERATION_SET("symmdiff", set_Filter1, set_Filter2);

            // check the result: if the list is NOT empty, there are errors
            KL_Result = KEYLIST_FROM_SET(set_Filter3);
            if(KL_Result.length > 0) {
                WRITE_OBJECTLIST(KL_Result, "Documents without exclusive material link");
                alert(KL_Result.length + " of the selected documents do NOT have an exclusive material link.");
            } else {
                alert("Successful!\nAll selected documents do have an exclusive material link.");
            }
        } else {
            alert("None of the selected documents have a material link.");
        }
    } else {
        alert("Select at least one document.");
    }
}

Accepted Solutions (1)

Accepted Solutions (1)

Hello Thomas,

please take a look at this Link:

https://wiki.scn.sap.com/wiki/display/PLM/How+to+find+assembly+components+with+ambiguous+material+li...

There you can find the filter parameter you need for this use case, although it is not "general purpose" DRAD filter.

By the way, for your use case you don't really need any macro. Just send you selection to object list, select object list and filter the table in ObjectBrowser on the material icon column.

Answers (1)

Answers (1)

Hi Waldemar,

Thanks, it worked!