Product configurator data structure

Even though AX 2012 uses the Microsoft Solver Foundation which is not directly accessible to a developer, all data is stored within AX and can be worked with at will. See the follow overview of the data structure:

AX 2012 Product Configurator

Note that most of the data is global, just the PCTemplateComponent table has company specific entries; the table is used for templates – as the name suggests – but also for the item references eg. for Configurator BOM lines.

Advertisements

Add document to record

Simple code snippet to add a document attachment to a record:

static void addDoc( Common common,
                    DocuTypeId docuTypeId,
                    FileName fileName)
{
    DocuRef docuRef;
    DocuValue docuValue;

    if(common && docuTypeId)
    {
        ttsBegin;
        docuRef.clear();
        docuRef.initValue();
        docuRef.TypeId = docuTypeId;
        docuRef.Name = filename;
        docuRef.RefRecId = common.RecId;
        docuRef.RefTableId = common.TableId;
        docuRef.RefCompanyId = curext();
        docuValue.initFromDocuRef(docuRef);
        docuValue.insert();
        docuRef.ValueRecId = docuValue.RecId;
        docuRef.insert();
        ttsCommit;
        if(filename)
        {
            DocuValue::writeDocuValue(docuRef,filename); //after ttsCommit to enable catching of file system errors
        }
    }
}

Edit System Fields

Simple example for creating a record with systems fields set by code:

protected static server CaseLog createCaseLog(RefRecId _caseDatail, CreatedBy _createdBy, CreatedDateTime _createdDateTime)
{
    CaseLog caseLog;
    if(_createdBy && _caseDatail)
    {
        caseLog.initValue();
        caseLog.CaseRecId = _caseDatail;
        new OverwriteSystemFieldsPermission().assert();
        caseLog.overwriteSystemfields(true);
        caseLog.(fieldNum(CaseLog,CreatedBy)) = _createdBy;
        caseLog.(fieldNum(CaseLog,CreatedDateTime)) = _createdDateTime;
        caseLog.doInsert();
        caseLog.overwriteSystemfields(false);
        CodeAccessPermission::revertAssert();
    }
    return caseLog;
}

Show configuration on hand

The constraint based configuration is saved in relation to the configuration-number (InventDim.ConfigId), however all you see in the On-Hand form is the number.

If you want to see the full configuration that was entered by the user, you can add a simple button to the On-hand form (InventOnhandItem) and override the clicked() method with the following code:

void clicked()
{
    PCExecuteVariantConfiguration executeVariantConfiguration;
    ProdTable                     tmpProdTable;

    tmpProdTable.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;
    tmpProdTable.ItemId      = InventSum.ItemId;

    if(PCRuntimeLibrary::isConstraintBasedConfigurable(InventSum.ItemId))
    {
        executeVariantConfiguration = PCExecuteVariantConfiguration::execute(tmpProdTable, InventSum.ItemId, inventDim.ConfigId);
    }
}

 

Result:

Open configuration from the on-hand form

Open configuration from the on-hand form

Comparison Framework Sample : BOM Version comparer

I found this blog post Comparison Framework Sample: BOM Version comparer.

Mkz creted a BOM version comparer based on the comparison framework tutorial allowing you to see the line by line differences between BOM versions. I made a quick upgrade to AX 2012 and it now compiles without best practice errors.

BOMComparer_AX2012.xpo