Action

View as Markdown

Action

Action describes what a field visibility rule does to one target field when its conditions match, for example show the field.

When to Use This Class: Use this class to fill the Actions list of a FieldRules object.

Conceptual Role: Acts as the data model of one item in the actions list of a field visibility rule.

Returns: Action. One action of a field visibility rule.

Properties

NameTypeRequiredDefaultDescription
statestring?NonullWhat the rule does to the target field, for example show. Serialized as action.
TargetFieldstring?NonullUID of the field the action applies to. Serialized as target_field.

Class-Level Notes

Names.

  • The property state is lowercase in the SDK and serializes as action.
  • The SDK names this class Action, the same name as System.Action. A file that has both using System; and using Contentstack.Management.Core.Models.Fields; gets an ambiguous reference error (CS0104) on Action. Add an alias such as using FieldAction = Contentstack.Management.Core.Models.Fields.Action;, or write the full name.
  • The Set Field Visibility Rule for Content Type request of the Content Management API reference describes the actions list.

Method Index

Action has no methods. Set its properties and add the object to FieldRules.Actions.

Class-Level Snippet

The snippet below updates a content type with a rule whose action shows the video URL field.

using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Fields;
using FieldAction = Contentstack.Management.Core.Models.Fields.Action;

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");

ContentModelling model = new ContentModelling
{
    Title = "Blog Post",
    Uid = "blog_post",
    Schema = new List<Field>
    {
        new TextboxField { DisplayName = "Title", Uid = "title", DataType = "text", Mandatory = true, Unique = true },
        new TextboxField { DisplayName = "Post Type", Uid = "post_type", DataType = "text" },
        new TextboxField { DisplayName = "Video URL", Uid = "video_url", DataType = "text" }
    },
    FieldRules = new List<FieldRules>
    {
        new FieldRules
        {
            MatchType = "all",
            conditions = new List<Condition>
            {
                new Condition { OperandField = "post_type", Operator = "equals", Value = "video" }
            },
            Actions = new List<FieldAction>
            {
                new FieldAction { state = "show", TargetField = "video_url" }
            }
        }
    }
};

try
{
    ContentstackResponse response = client.Stack("<API_KEY>").ContentType("blog_post").Update(model);
    Console.WriteLine(response.OpenJsonObjectResponse()["notice"]);
}
catch (ContentstackErrorException e)
{
    // Thrown when the API rejects the request
    Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}