Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: FormContext and Statecode #82

Open
DSTAlan opened this issue Apr 4, 2022 · 1 comment
Open

Question: FormContext and Statecode #82

DSTAlan opened this issue Apr 4, 2022 · 1 comment

Comments

@DSTAlan
Copy link

DSTAlan commented Apr 4, 2022

What is the correct way to add a statecode attribute to the formContext? I have been creating string attributes as shown in the examples i.e.

const stringAttribute = XrmMockGenerator.Attribute.createString("firstname", "Joe");

Then adding them to the formContext like

context.data.attributes = new ItemCollectionMock([stringAttribute]);

If I try to create a statecode though as below

const statecode = XrmMockGenerator.Attribute.createOptionSet("statecode", 0, [
  { text: "Active", value: 0 },
  { text: "Inactive", value: 1 },
]);

I get an error about a circular reference.

Thanks, Alan

@maichopra
Copy link

Try this.

import { describe, it, expect, beforeEach } from "vitest";
import { XrmMockGenerator, OptionSetAttributeMock, ItemCollectionMock } from "xrm-mock";

describe("Issue 82", () => {
    beforeEach(() => {
        // Initialize XRM Mock
        const Xrm = XrmMockGenerator.initialise();
    });

    it("FormContext and Statecode", () => {
        const context = XrmMockGenerator.getEventContext();
        const formContext = context.getFormContext();

        const statecode = XrmMockGenerator.Attribute.createOptionSet("statecode", 0, [
            { text: "Active", value: 0 },
            { text: "Inactive", value: 1 },
        ]);

        // Add statecode to form attributes
        formContext.data.attributes = new ItemCollectionMock([statecode]);

        // Confirm it is correctly added
        console.log(formContext.data.attributes.get("statecode").getValue()); // Output: 0
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants