Skip to content

How to Create Custom Context Types

To create a custom context type with Vault Java SDK:

  1. Create a Context Type Runtime Handler:

    @ExecuteAs(ExecuteAsUser.REQUEST_OWNER)
    @AiContextTypeRuntimeHandlerInfo(scope = AiScope.DOCUMENT)
    public class MyContextTypeRuntimeHandler implements AiContextTypeRuntimeHandler{
        @Override
        public AiContextTypeResolveResponse onResolve(AiContextTypeResolveContext context){
            AiDocumentScopeSource documentScopeSource = context.getScopeSource(AiScopeType.DOCUMENT);
            DocumentVersion documentVersion = documentScopeSource.getDocumentVersion();
            String documentName = documentVersion.getValue("name__v", ValueType.STRING);
    
            AiContextTypeOutputItem contextOutput = context.newOutputItemBuilder()
                .withText("The current document name is [" + documentName + "]")
                .build();
    
            return context.newSuccessResponseBuilder()
                .appendOutputItem(contextOutput)
                .build();
             }
         }
  2. Create an Aicontexttyperuntimecode MDL record referencing the AiContextTypeRuntimeHandler, and create an Aicontexttype MDL record:

    RECREATE Aicontexttype my_custom_context_type__c (
    label('My Context Type'),
    admin_configurable(true),
    runtime_code('Aicontexttyperuntimecode.com.veeva.vault.custom.context.MyContextTypeRuntimeHandler')
          );